本文翻译自: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: 此外,如果您要检查是否有compile
, testCompile
和androidTestCompile
依赖项以及将其提取的原因:
./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
#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. 通常,完整的test
, compile
和androidTestCompile
依赖图太多,无法一起检查。 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 请在这里看到这个答案