使用gradle查找依赖树

这篇博客介绍了如何使用Gradle命令来生成项目依赖树,帮助开发者了解并优化项目中的依赖关系。对于Android项目,特定的命令行选项被提及,同时提到了在Android Studio中进行同样操作的方法。此外,还讨论了如何生成HTML报告以便更方便地查看依赖结构,并提醒开发者注意Gradle命令的更新和依赖项的最佳实践。
摘要由CSDN通过智能技术生成

本文翻译自:Using gradle to find dependency tree

Is it possible to use gradle to produce a tree of what depends on what? 是否可以使用gradle生成取决于什么的树?

I have a project and would like to find out all the dependencies so I may be able to prune it a little with forward declarations etc. 我有一个项目,想找出所有的依赖关系,这样我就可以使用前向声明等对其进行一些修剪。


#1楼

参考:https://stackoom.com/question/1Sos3/使用gradle查找依赖树


#2楼

You can render the dependency tree with the command gradle dependencies . 您可以使用命令gradle dependencies渲染依赖性树。 For more information check the section 11.6.4 Listing project dependencies in the online user guide. 有关更多信息,请参见在线用户指南中的11.6.4列出项目依赖项


#3楼

For Android, use this line 对于Android,使用此行

 gradle app:dependencies

or if you have a gradle wrapper: 或者,如果您有gradle包装器:

./gradlew app:dependencies

where app is your project module. app是您的项目模块。

Additionally, if you want to check if something is compile vs. testCompile vs androidTestCompile dependency as well as what is pulling it in: 此外,如果您要检查是否有compiletestCompileandroidTestCompile依赖项以及将其提取的原因:

./gradlew :app:dependencyInsight --configuration compile --dependency <name>
./gradlew :app:dependencyInsight --configuration testCompile --dependency <name>
./gradlew :app:dependencyInsight --configuration androidTestCompile --dependency <name>

#4楼

If you find it hard to navigate console output of gradle dependencies , you can add the Project reports plugin : 如果发现很难导航gradle dependencies控制台输出, gradle dependencies可以添加“ 项目报告”插件

apply plugin: 'project-report'

And generate a HTML report using: 并使用以下命令生成HTML报告:

$ ./gradlew htmlDependencyReport

Report can normally be found in build/reports/project/dependencies/index.html 通常可以在build/reports/project/dependencies/index.html找到build/reports/project/dependencies/index.html

It looks like this: 看起来像这样: 在此处输入图片说明


#5楼

In Android Studio 在Android Studio中

1) Open terminal and ensure you are at project's root folder. 1)打开终端,并确保您位于项目的根文件夹中。

2) Run ./gradlew app:dependencies (if not using gradle wrapper, try gradle app:dependencies ) 2)运行./gradlew app:dependencies (如果不使用gradle包装器,请尝试gradle app:dependencies

Note that running ./gradle dependencies will only give you dependency tree of project's root folder, so mentioning app in above manner, ie ./gradlew app:dependencies is important. 请注意,运行./gradle dependencies只会给您项目根文件夹的依赖树,因此以上述方式提及应用程序,即./gradlew app:dependencies很重要。


#6楼

Often the complete test , compile , and androidTestCompile dependency graph is too much to examine together. 通常,完整的testcompileandroidTestCompile依赖图太多,无法一起检查。 If you merely want the compile dependency graph you can use: 如果仅需要compile依赖关系图,则可以使用:

./gradlew app:dependencies --configuration compile

Source: Gradle docs section 4.7.6 来源: Gradle文档第4.7.6节

Note: compile has been deprecated in more recent versions of Gradle and in more recent versions you are advised to shift all of your compile dependencies to implementation . 注: compile已被弃用,在较新版本的摇篮,并在建议您所有的转向较新版本的compile依赖于implementation Please see this answer here 在这里看到这个答案

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值