سؤال

I followed this example to get the required dependencies injected into my AbtractMavenLifecyleParticipant:

The 'afterProjectsRead' get called perfectly, but repoSystem, repoSession and remoteRepos where always 'null'.

How can I get hold on these objects from within a 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);

    }
}
هل كانت مفيدة؟

المحلول

This is how we do it in 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
);

Maybe you can just use the library, instead of writing it yourself..

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top