How to use Aether in a org.apache.maven.AbstractMavenLifecycleParticipant
-
28-06-2021 - |
Domanda
I followed this example to get the required dependencies injected into my AbtractMavenLifecyleParticipant:
http://www.sonatype.com/people/2011/01/how-to-use-aether-in-maven-plugins/
http://maven.apache.org/examples/maven-3-lifecycle-extensions.html
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);
}
}
Soluzione
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..
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow