Maven3:如何获取自定义 Maven 扩展中的所有项目依赖项
在 Maven 3.x 中,如何获取项目的所有依赖项,包括自定义 Maven 扩展中的传递性(不使用 Aether)
In Maven 3.x , how I can get all the dependencies of a project including the transitive in a custom maven extension (By not using Aether)
目前我有这个:
@Component(role = AbstractMavenLifecycleParticipant.class, hint = "Test")
public class sampleExtension extends AbstractMavenLifecycleParticipant implements LogEnabled {
private Logger logger;
@Override
public void afterSessionStart(MavenSession session)
throws MavenExecutionException {
this.logger.info("Starting afterSessionStart()");
}
@Override
public void afterProjectsRead(MavenSession session)
throws MavenExecutionException {
MavenProject pr = session.getCurrentProject();
List dependencies = pr.getDependencies();
this.logger.info("Project name and Size of dependencies: " + pr.getArtifactId() + " : " + dependencies.size());
}
@Override
public void enableLogging(Logger logger) {
this.logger = logger;
}
}
我正在构建这个扩展 jar 并将它放在 $Maven_home/lib/ext 中.我随机选择了一个 maven 项目(我们称之为abc")并运行命令: mvn clean install ,它从日志中将依赖项的数量显示为 13.就像我在 'abc' 上运行 mvn dependency:copy-dependencies 一样,我看到 200 多个依赖项复制到目标文件夹.
I am building this extension jar and placing it in $Maven_home/lib/ext . I picked up a random maven project (lets call it 'abc') and ran the command : mvn clean install , which shows the number of dependencies as 13 from the logs. Where as if I run mvn dependency:copy-dependencies on 'abc' , I see more than 200 dependencies copied to target folder.
最终,我想做的是,在扩展类中获取一个项目的所有依赖项,并将其复制到一个文件夹中.
Ultimately, what I want to do is, get all the dependencies of a project in the extension class and copy it to a folder.
我做错了什么吗?请注意,我对这一切都很陌生.非常感谢任何帮助.
Is there anything I am doing wrong? Please note that I am new to all this. Any help is greatly appreciated.
@Mojo(name = "xxx", defaultPhase = LifecyclePhase.xxx, requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
@Mojo(name = "xxx", defaultPhase = LifecyclePhase.xxx, requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)