我按照这个例子将所需的依赖项注入到我的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
'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);
}
}
答案 0 :(得分: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
);
也许您可以使用该库,而不是自己编写..