是否有可能使用Gradle生成一个什么依赖什么的树?

我有一个项目,想要找出所有的依赖,所以我可以用前向声明等修剪它一点。


当前回答

如果你发现很难导航控制台输出的gradle依赖项,你可以添加项目报告插件:

apply plugin: 'project-report'

并生成一个HTML报告使用:

$ ./gradlew htmlDependencyReport

Report通常可以在build/reports/project/dependencies/index.html中找到

它是这样的:

其他回答

在Android Studio中

1)打开终端,确保你在项目的根文件夹。

2)运行。/gradlew app:dependencies(如果没有使用gradle wrapper,尝试gradle app:dependencies)

注意,运行。/gradle dependencies只会给你项目根文件夹的依赖树,所以以上述方式提到app,即./gradlew app:dependencies是很重要的。

如果你发现很难导航控制台输出的gradle依赖项,你可以添加项目报告插件:

apply plugin: 'project-report'

并生成一个HTML报告使用:

$ ./gradlew htmlDependencyReport

Report通常可以在build/reports/project/dependencies/index.html中找到

它是这样的:

没有模块:

gradle dependencies

为Android:

 gradle app:dependencies

使用gradle包装:

./gradlew app:dependencies

注意:将app替换为项目模块名。

此外,如果你想检查某个东西是否依赖于compile vs. testCompile vs. androidTestCompile,以及是什么把它拉进来的:

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

通常完整的testimplemimplementation、实现和androidtestimplemimplementation依赖关系图太多了,不能一起检查。如果你只是想要实现依赖关系图,你可以使用:

./gradlew app:dependencies --configuration implementation

来源:列出项目中的依赖项

注意:compile在最近的Gradle版本中已经被弃用,在最近的版本中,建议你将所有的compile依赖项转移到实现中。请看这里的答案

注意,如果模块在到达build.gradle之前有额外的目录,您可能需要执行类似于./gradlew <module_directory>:<module_name>:dependencies的操作。如果有疑问,执行./gradlew任务——所有这些都是为了检查名称。