在调试我正在编写的插件时,我遇到了maven-project依赖解析的问题。
我的项目依赖于版本2.0.8,maven-dependency-plugin:相同版本的2.8分,但在Eclipse中随机行突出显示在MavenProject类的源代码中。
我已经尝试找到一个合适的版本,感觉正在使用3.0-alphas之一
Maven是否有可能提供甚至更高版本的maven-project由maven本身使用(例如3.0-alpha-2),但是Eclipse无法解决这个问题?
顺便说一句:我已经尝试用maven-project找到一个回购并没有这样做。在哪里维护。更新: 我的依赖项:
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0.8</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-exec</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0.8</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.twdata.maven</groupId>
<artifactId>mojo-executor</artifactId>
<version>2.1.0</version>
</dependency>
</dependencies>
在我的PrepareDependenciesMojo中,我像这样运行mojo-executor:
@Mojo( name = "prepare-dependencies", requiresDependencyResolution = ResolutionScope.COMPILE )
public class PrepareDependenciesMojo
extends AbstractMojo
{
@Parameter( defaultValue = "${project}", readonly = true, required = true )
private MavenProject project;
@Parameter( defaultValue = "${session}", readonly = true, required = true )
private MavenSession session;
@Component( role = BuildPluginManager.class )
private BuildPluginManager pluginManager;
/**
* Based on dependencies entered, selects what to copy and what to copy and unpack.
*
* @throws MojoExecutionException .
* @throws MojoFailureException when plugin execution result was other than expected
* @see org.apache.maven.plugin.Mojo#execute()
*/
public void execute()
throws MojoExecutionException, MojoFailureException
{
executeMojoWithLogs( "org.apache.maven.plugins", "maven-dependency-plugin", "2.8", "copy-dependencies",
configuration() );
executeMojoWithLogs( "org.apache.maven.plugins", "maven-dependency-plugin", "2.8", "unpack-dependencies",
configuration() );
}
private void executeMojoWithLogs( String groupId, String artifactId, String version, String goal,
Xpp3Dom configuration )
throws MojoExecutionException
{
getLog().info( String.format( "--- %s:%s:%s (call within prepare-dependencies) @ empty-project ---",
artifactId, version, goal ) );
getLog().debug( configuration.toString() );
executeMojo(
plugin(
groupId( groupId ),
artifactId( artifactId ),
version( version )
),
goal( goal ),
configuration,
executionEnvironment( project, session, pluginManager ) );
getLog().info( String.format( "--- %s:%s:%s ended ---",
artifactId, version, goal ) );
}
}
我在复制依赖项中输入了doExecute,但在其中,第一个方法从MavenProject中检索工件 - 在那里我获得了依赖项的不正确的源代码。