我按照这个示例将所需的依赖项注入到我的 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);
}
}