3

我正在使用 API v3.1.1 开发一个新的 Maven 插件,因为我需要升级到 Maven 3.1.1,并且需要 Aether 方式来处理工件存储库,以及检索工件版本的完整列表。我使用的是 Eclipse Aether (0.9.0.M4),而不是Sonatype Aether。

我已经阅读了http://wiki.eclipse.org/Aether并尝试了演示http://git.eclipse.org/c/aether/aether-demo.git/tree/,但我无法了解为什么子类中AbstractMojo以下内容不起作用。

RepositorySystem repoSystem, RepositorySystemSession repoSession,List<RemoteRepository> projectRepos和都是. List<RemoteRepository> pluginRepos_null

我也尝试过使用@Component注入具有相同结果的那些。

为了将这些对象注入 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
    ...
}
4

1 回答 1

2

最后,它对我有用,我认为它之前不起作用的原因是我的 pom.xml 中有太多依赖项,并且事情没有得到正确解决。

这是我用来使原始帖子中的代码正常工作的完整 pom.xml。其余代码来自 aether-demo,其链接也在原帖中提供

<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>
于 2014-02-12T07:17:20.483 回答