英文:
Get all 3rd Party dependencies module is using in Maven
问题
我们有一个多模块的Maven项目。我有一个使用案例,我想知道如何获取代码中使用的所有依赖项列表以及它们的版本:
- 如果它在pom中声明并被使用。
- 如果没有在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:
- If its declared in pom and being used.
- 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
依赖插件提供了操作构件的能力。它可以从本地或远程存储库复制和/或解压构件到指定位置。
以及它的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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论