是否可以使用gradle来生成依赖于什么的树?
我有一个项目,想要找出所有的依赖项,所以我可以通过前向声明等来修改它 .
在Android Studio中
1)打开终端并确保您在项目的根文件夹中 .
2)运行 ./gradlew app:dependencies (如果不使用gradle包装器,请尝试 gradle app:dependencies )
./gradlew app:dependencies
gradle app:dependencies
请注意,运行 ./gradle dependencies 只会为您提供项目根文件夹的依赖关系树,因此以上述方式提及应用程序,即 ./gradlew app:dependencies 非常重要 .
./gradle dependencies
您可以使用命令 gradle dependencies 呈现依赖关系树 . 有关更多信息,请查看在线用户指南中的11.6.4 Listing project dependencies部分 .
gradle dependencies
如果要在图形中可视化依赖项,可以使用gradle-dependency-graph-generator插件 .
真实应用程序中的依赖图示例(Chess Clock):
对于Android,请使用此行
或者如果你有一个gradle包装器:
其中 app 是您的项目模块 .
app
另外,如果你想检查某些东西是否是 compile 与 testCompile vs androidTestCompile 依赖关系以及拉入的内容:
compile
testCompile
androidTestCompile
./gradlew :app:dependencyInsight --configuration compile --dependency <name> ./gradlew :app:dependencyInsight --configuration testCompile --dependency <name> ./gradlew :app:dependencyInsight --configuration androidTestCompile --dependency <name>
如果您发现很难导航 gradle dependencies 的控制台输出,则可以添加Project reports plugin:
apply plugin: 'project-report'
并使用以下方法生成HTML报告:
$ ./gradlew htmlDependencyReport
报告通常可以在 build/reports/project/dependencies/index.html 找到
build/reports/project/dependencies/index.html
它看起来像这样:
请注意,如果模块在到达build.gradle之前有额外的目录,则可能需要执行 ./gradlew <module_directory>:<module_name>:dependencies 之类的操作 . 如有疑问,请执行 ./gradlew tasks --all 检查名称 .
./gradlew <module_directory>:<module_name>:dependencies
./gradlew tasks --all
我发现运行它也很有用:
./gradlew dI --dependency <your library>
这显示了如何解析依赖关系( dependencyInsight )并帮助您调试到 build.gradle 中需要强制或排除库的位置
dependencyInsight
build.gradle
见:https://docs.gradle.org/current/userguide/tutorial_gradle_command_line.html
在Android Studio中(至少从v2.3.3开始),您可以直接从UI运行命令:
单击Gradle选项卡,然后双击:yourmodule - > Tasks - > android - > androidDependencies
树将显示在Gradle Console选项卡中
通常,完整的 test , compile 和 androidTestCompile 依赖关系图太多而无法一起检查 . 如果您只想要 compile 依赖图,则可以使用:
test
./gradlew app:dependencies --configuration compile
资料来源:Gradle docs section 4.7.6
注意:在最新版本的Gradle中已弃用 compile ,在更新版本中,建议您将所有 compile 依赖项移至 implementation . 请参阅this answer here
implementation
9 回答
在Android Studio中
1)打开终端并确保您在项目的根文件夹中 .
2)运行
./gradlew app:dependencies
(如果不使用gradle包装器,请尝试gradle app:dependencies
)请注意,运行
./gradle dependencies
只会为您提供项目根文件夹的依赖关系树,因此以上述方式提及应用程序,即./gradlew app:dependencies
非常重要 .您可以使用命令
gradle dependencies
呈现依赖关系树 . 有关更多信息,请查看在线用户指南中的11.6.4 Listing project dependencies部分 .如果要在图形中可视化依赖项,可以使用gradle-dependency-graph-generator插件 .
真实应用程序中的依赖图示例(Chess Clock):
对于Android,请使用此行
或者如果你有一个gradle包装器:
其中
app
是您的项目模块 .另外,如果你想检查某些东西是否是
compile
与testCompile
vsandroidTestCompile
依赖关系以及拉入的内容:如果您发现很难导航
gradle dependencies
的控制台输出,则可以添加Project reports plugin:并使用以下方法生成HTML报告:
报告通常可以在
build/reports/project/dependencies/index.html
找到它看起来像这样:
请注意,如果模块在到达build.gradle之前有额外的目录,则可能需要执行
./gradlew <module_directory>:<module_name>:dependencies
之类的操作 . 如有疑问,请执行./gradlew tasks --all
检查名称 .我发现运行它也很有用:
这显示了如何解析依赖关系(
dependencyInsight
)并帮助您调试到build.gradle
中需要强制或排除库的位置见:https://docs.gradle.org/current/userguide/tutorial_gradle_command_line.html
在Android Studio中(至少从v2.3.3开始),您可以直接从UI运行命令:
单击Gradle选项卡,然后双击:yourmodule - > Tasks - > android - > androidDependencies
树将显示在Gradle Console选项卡中
通常,完整的
test
,compile
和androidTestCompile
依赖关系图太多而无法一起检查 . 如果您只想要compile
依赖图,则可以使用:资料来源:Gradle docs section 4.7.6
注意:在最新版本的Gradle中已弃用
compile
,在更新版本中,建议您将所有compile
依赖项移至implementation
. 请参阅this answer here