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

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


当前回答

对于Android,在终端中输入这个

gradlew app:dependencies

它将列出所有的依赖项和更新版本的依赖项,供您升级

com.android.support:customtabs:26.1.0 -> 27.1.1 (*)

其他回答

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

apply plugin: 'project-report'

并生成一个HTML报告使用:

$ ./gradlew htmlDependencyReport

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

它是这样的:

对于最新版本的Gradle(我使用6.4.1版本进行测试):

gradle dependencies --configuration compileClasspath

或者如果你正在使用Gradle Wrapper:

gradlew dependencies --configuration compileClasspath

当使用'debug'和'release'编译配置文件为Android构建时,可以使用debugCompileClasspath和releaseCompileClasspath配置来代替compileClasspath。

没有模块:

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>

在Android Studio中(至少从v2.3.3开始),你可以直接从UI运行命令:

点击Gradle选项卡,然后双击:yourmodule -> Tasks -> android -> androidDependencies

该树将显示在Gradle Console选项卡中

双击并在gradle视图的帮助下运行依赖项