How to get “relocated” or resolved artifact ID from top-level dependencies in maven plugin

大憨熊 提交于 2019-12-08 04:50:23

问题


I may be going about this wrong, but I'm trying to get the top-level dependencies of a project within a maven plugin.

I can get all (top-level and transitive) dependencies using this call

MavenProject.getArtifacts()

I can get just the top-level dependencies using this call

MavenProject.getDependencyArtifacts()

The problem is that the artifactIds returned in the latter call is sometimes different than the artifactIds in the former call. This happens when the dependency is "relocated" such as xerces:xerces:2.4.0

 <project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>xerces</groupId>
  <artifactId>xerces</artifactId>
  <version>2.4.0</version>
  <distributionManagement>
    <relocation>
      <groupId>xerces</groupId>
      <artifactId>xercesImpl</artifactId>
    </relocation>
  </distributionManagement>
 </project>

If the developer specifies xerces:xerces:2.4.0 in their pom, getArtifacts() returns xerces:xercesImpl. But getDependencyArtifacts() returns xerces:xerces.

来源:https://stackoverflow.com/questions/36757645/how-to-get-relocated-or-resolved-artifact-id-from-top-level-dependencies-in-ma

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!