【问题标题】:How to use Aether in a org.apache.maven.AbstractMavenLifecycleParticipant如何在 org.apache.maven.AbstractMavenLifecycleParticipant 中使用 Aether
【发布时间】:2012-08-27 19:10:04
【问题描述】:

我按照这个示例将所需的依赖项注入到我的 AbtractMavenLifecyleParticipant 中:

“afterProjectsRead”被完美调用,但 repoSystem、repoSession 和 remoteRepos 始终为“null”。

如何从 AbstractMavenLifecyleParticipant 中获取这些对象?

import org.apache.maven.AbstractMavenLifecycleParticipant;
import org.apache.maven.MavenExecutionException;
import org.apache.maven.execution.MavenSession;
import org.codehaus.plexus.component.annotations.Component;
import org.sonatype.aether.RepositorySystem;
import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.repository.RemoteRepository;

@Component(role = AbstractMavenLifecycleParticipant.class, hint = "skipper")
public class ModuleSkipperLifecycleParticipant extends AbstractMavenLifecycleParticipant {

    /**
     * @component
     */
    private RepositorySystem repoSystem;

    /**
     * @parameter default-value="${repositorySystemSession}"
     * @readonly
     */
    private RepositorySystemSession repoSession;

    /**
     * @parameter default-value="${project.remotePluginRepositories}"
     * @readonly
     */
    private List<RemoteRepository> remoteRepos;

    @Override
    public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
        super.afterProjectsRead(session);

        System.out.println("repoSession: " + repoSession);
        System.out.println("repoSystem: " + repoSystem);
        System.out.println("remoteRepos: " + remoteRepos);

    }
}

【问题讨论】:

    标签: maven maven-3 maven-plugin aether


    【解决方案1】:

    这就是我们在jcabi-aether 中的做法:

    final File repo = this.session.getLocalRepository().getBasedir();
    final Collection<Artifact> deps = new Aether(this.getProject(), repo).resolve(
      new DefaultArtifact("junit", "junit-dep", "", "jar", "4.10"),
      JavaScopes.RUNTIME
    );
    

    也许您可以只使用该库,而不是自己编写它..

    【讨论】:

    • 看起来不错,第一个测试似乎有效-我将对其进行更详细的测试。非常感谢现在!!!!!!
    • 虽然我不会使用这个库,但它给了我正确的提示 - 谢谢!
    猜你喜欢
    • 2023-03-17
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 2014-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多