如何使用API 3.1.1在Maven插件中使用Aether(eclipse)? [英] How to use Aether (eclipse) in Maven Plugins using API 3.1.1?
问题描述
我正在使用API v3.1.1开发一个新的Maven插件,因为我需要升级到Maven 3.1.1,并且需要以Aether方式处理工件存储库,以及检索工件版本的完整列表。我正在使用Eclipse Aether(0.9.0.M4), NOT Sonatype Aether。
I am developing a new Maven plugin using API v3.1.1 because I need to upgrade to Maven 3.1.1, and need the Aether way of dealing with artifact repositories, among other things retrieving the complete list of artifact versions. I am using Eclipse Aether (0.9.0.M4), NOT Sonatype Aether.
我已经阅读了 http://wiki.eclipse.org/Aether 并尝试了演示 http://git.eclipse.org/c/aether/aether-demo.git/tree/ ,但我有无法理解为什么以下在 AbstractMojo
的子类中不起作用。
I have already read through http://wiki.eclipse.org/Aether and tried the demos http://git.eclipse.org/c/aether/aether-demo.git/tree/, but I have not been able to understand why the following within a subclass of AbstractMojo
doesn't work.
两者 RepositorySystem repoSystem
, RepositorySystemSession repoSession
,列表与LT; RemoteRepository> projectRepos
和 List< RemoteRepository> pluginRepos
是 null
。
我也尝试过使用 @Component
注入具有相同结果的那些。
I have also tried using @Component
to inject those with the same result.
为了将这些对象注入mojo,有什么我错过了吗?
Is there anything I has missed out in order to get those objects injected into the mojo?
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RemoteRepository;
...
public MyMojo extends AbstractMojo
{
/**
* The entry point to Aether, i.e. the component doing all the work.
*
* @component
*/
private RepositorySystem repoSystem;
/**
* The current repository/network configuration of Maven.
*
* @parameter default-value="${repositorySystemSession}"
* @readonly
*/
private RepositorySystemSession repoSession;
/**
* The project's remote repositories to use for the resolution of project dependencies.
*
* @parameter default-value="${project.remoteProjectRepositories}"
* @readonly
*/
private List<RemoteRepository> projectRepos;
/**
* The project's remote repositories to use for the resolution of plugins and their dependencies.
*
* @parameter default-value="${project.remotePluginRepositories}"
* @readonly
*/
private List<RemoteRepository> pluginRepos;
// Your other mojo parameters and code here
...
}
推荐答案
最后,它对我有用,我之前认为它不起作用的原因是我的pom.xml和东西中有太多依赖项没有得到正确解决。
Finally, it worked for me, and the reason I think it didn't work earlier was that I had too many dependencies in my pom.xml and things didn't get resolved correctly.
这是我使用的完整pom.xml,以便原始帖子中的代码能够正常工作。其余代码用于aether-demo,其链接也在原始帖子中提供
Here is the complete pom.xml I used in order for the code in the original post to work. Rest of the code was used from the aether-demo, the link of which is also provided in the original post
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>aether.example</groupId>
<artifactId>my-aether-plugin</artifactId>
<version>1.0.1-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mavenVersion>3.1.1</mavenVersion>
<aetherVersion>0.9.0.M4</aetherVersion>
<mavenPluginVersion>3.2</mavenPluginVersion>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>${mavenPluginVersion}</version>
<configuration>
<goalPrefix>my-aether</goalPrefix>
<!-- see http://jira.codehaus.org/browse/MNG-5346 -->
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
<executions>
<execution>
<id>mojo-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
<execution>
<id>help-goal</id>
<goals>
<goal>helpmojo</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${mavenVersion}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.plexus</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-api</artifactId>
<version>${aetherVersion}</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-util</artifactId>
<version>${aetherVersion}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
这篇关于如何使用API 3.1.1在Maven插件中使用Aether(eclipse)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!