获取Maven中模块正在使用的所有第三方依赖项。

huangapple go评论84阅读模式
英文:

Get all 3rd Party dependencies module is using in Maven

问题

我们有一个多模块的Maven项目。我有一个使用案例,我想知道如何获取代码中使用的所有依赖项列表以及它们的版本:

  1. 如果它在pom中声明并被使用。
  2. 如果没有在pom中声明,但仍然被使用(通过传递导入)。

如果方法可以排除在pom中声明但在代码中未被使用的依赖项,那将是额外的好处。

请建议实现这一目标的最佳方法。谢谢!

英文:

We have a multi-module maven project. I have a use case where I want to know to get a list of all the dependencies which is being used in code with version:

  1. If its declared in pom and being used.
  2. Not declared in pom but still being used (transitively imported).

Bonus would be if the approach can exclude the deps which are being declared in pom but not being used in the code.

Please suggest the best way to achieve this. TIA.

答案1

得分: 2

只需使用mvn dependency:tree命令。

英文:

Just use the mvn dependency:tree command.

答案2

得分: 2

这里有Maven Dependency Plugin

依赖插件提供了操作构件的能力。它可以从本地或远程存储库复制和/或解压构件到指定位置。

以及它的tree目标:

显示此项目的依赖关系树。

关于您的奖励,还有analyze目标:

分析此项目的依赖关系,并确定哪些是:已使用和已声明的;已使用但未声明的;未使用但已声明的。

以及analyze-only目标:

与analyze相同,但用于在pom中绑定。它不会分叉构建并执行test-compile。

英文:

There's the Maven Dependency Plugin:

> The dependency plugin provides the capability to manipulate artifacts. It can copy and/or unpack artifacts from local or remote repositories to a specified location.

with its tree goal:

> Displays the dependency tree for this project.

Regarding your bonus there's the analyze goal:

> analyzes the dependencies of this project and determines which are: used and declared; used and undeclared; unused and declared.

and the analyze-only goal:

> is the same as analyze, but is meant to be bound in a pom. It does not fork the build and execute test-compile.

huangapple
  • 本文由 发表于 2020年8月10日 03:39:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/63330604.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定