是否有可能使用Gradle生成一个什么依赖什么的树?
我有一个项目,想要找出所有的依赖,所以我可以用前向声明等修剪它一点。
是否有可能使用Gradle生成一个什么依赖什么的树?
我有一个项目,想要找出所有的依赖,所以我可以用前向声明等修剪它一点。
当前回答
对于最新版本的Gradle(我使用6.4.1版本进行测试):
gradle dependencies --configuration compileClasspath
或者如果你正在使用Gradle Wrapper:
gradlew dependencies --configuration compileClasspath
当使用'debug'和'release'编译配置文件为Android构建时,可以使用debugCompileClasspath和releaseCompileClasspath配置来代替compileClasspath。
其他回答
通常完整的testimplemimplementation、实现和androidtestimplemimplementation依赖关系图太多了,不能一起检查。如果你只是想要实现依赖关系图,你可以使用:
./gradlew app:dependencies --configuration implementation
来源:列出项目中的依赖项
注意:compile在最近的Gradle版本中已经被弃用,在最近的版本中,建议你将所有的compile依赖项转移到实现中。请看这里的答案
对于最新版本的Gradle(我使用6.4.1版本进行测试):
gradle dependencies --configuration compileClasspath
或者如果你正在使用Gradle Wrapper:
gradlew dependencies --configuration compileClasspath
当使用'debug'和'release'编译配置文件为Android构建时,可以使用debugCompileClasspath和releaseCompileClasspath配置来代替compileClasspath。
我还发现运行这个很有用:
./gradlew dI --dependency <your library>
这显示了如何解析依赖关系(dependencyInsight),并帮助你调试到需要在build.gradle中强制或排除库的位置
参见:https://docs.gradle.org/current/userguide/tutorial_gradle_command_line.html
如果你发现很难导航控制台输出的gradle依赖项,你可以添加项目报告插件:
apply plugin: 'project-report'
并生成一个HTML报告使用:
$ ./gradlew htmlDependencyReport
Report通常可以在build/reports/project/dependencies/index.html中找到
它是这样的:
你可以使用gradle dependencies命令来呈现依赖树。有关更多信息,请查看在线用户指南中列出项目中的依赖项一节。