我有一个自定义maven插件.为了检索项目的依赖项,我使用
jcabi-aether库.它适用于获取项目范围依赖项.但我需要的是解决插件范围依赖关系,以便调用看起来像:
<plugin>
<groupId>com.maven</groupId>
<artifactId>some-maven-plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<configuration>
<some>${some}/path</some>
</configuration>
<dependencies>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.8.1</version>
<classifier>sources</classifier>
</dependency>
</dependencies>
</plugin>
...
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-aether</artifactId>
<version>0.10.1</version>
</dependency>
有人有什么想法吗?
谢谢
最佳答案 要从自定义Mojo的execute方法检索插件范围依赖项,您需要循环遍历构建的元素,如下所示:
Build build = super.getProject().getBuild();
if (null != build) {
List<Plugin> plugins = build.getPlugins();
for (Plugin plugin : plugins) {
List<Dependency> dependencies = plugin.getDependencies();
// you can then use your custom code here or just collected them for later usage.
// An example of what you can get, below
for (Dependency dependency : dependencies) {
getLog().info(dependency.getGroupId());
getLog().info(dependency.getArtifactId());
getLog().info(dependency.getVersion());
getLog().info(dependency.getClassifier());
getLog().info(dependency.getScope());
// etc.
}
}
}
一旦你拥有它们,我相信你可以使用Aether API来获得传递依赖关系,就像你已经为项目依赖关系所做的那样.