获取构建信息 - 获取依赖列表

优质
小牛编辑
132浏览
2023-12-01

执行 gradle dependencies 命令会列出项目的依赖列表, 所有依赖会根据任务区分,以树型结构展示出来.
如下例:

例 11.13. 获取依赖信息

gradle -q dependencies api:dependencies webapp:dependencies 的输出结果

  1. > gradle -q dependencies api:dependencies webapp:dependencies
  2. ------------------------------------------------------------
  3. Root project
  4. ------------------------------------------------------------
  5. No configurations
  6. ------------------------------------------------------------
  7. Project :api - The shared API for the application
  8. ------------------------------------------------------------
  9. compile
  10. --- org.codehaus.groovy:groovy-all:2.3.3
  11. testCompile
  12. --- junit:junit:4.11
  13. --- org.hamcrest:hamcrest-core:1.3
  14. ------------------------------------------------------------
  15. Project :webapp - The Web application implementation
  16. ------------------------------------------------------------
  17. compile
  18. +--- project :api
  19. | --- org.codehaus.groovy:groovy-all:2.3.3
  20. --- commons-io:commons-io:1.2
  21. testCompile
  22. No dependencies

虽然输出结果很多,
但这对于了解构建任务十分有用,
当然你可以通过 --configuration 参数来查看 指定构建任务的依赖情况:

例 11.14. 过滤依赖信息

gradle -q api:dependencies --configuration testCompile 的输出结果

  1. > gradle -q api:dependencies --configuration testCompile
  2. ------------------------------------------------------------
  3. Project :api - The shared API for the application
  4. ------------------------------------------------------------
  5. testCompile
  6. --- junit:junit:4.11
  7. --- org.hamcrest:hamcrest-core:1.3