【问题标题】:make gradle dependency task to exclude test dependencies in its result制作 gradle 依赖任务以在其结果中排除测试依赖项
【发布时间】:2020-11-11 12:23:34
【问题描述】:

当我运行 ./gradlew dependencies 时,我得到了整个依赖树,包括 prod/main 和 test。

如何在 dependencies 任务的结果中获取仅生产/主要依赖项的列表

官方文档https://docs.gradle.org/current/userguide/viewing_debugging_dependencies.html 建议如何显示特定配置所需的依赖项,例如 Java 项目中的测试运行时类路径:

`gradle -q dependencies --configuration testRuntimeClasspath`

谷歌搜索后,我找到了命令gradlew dependencies --configuration compileClasspath 它的结果是否也会包含运行时依赖项?

如何获取依赖项列表,不包括依赖项任务结果中的测试依赖项?

【问题讨论】:

    标签: java gradle gradlew gradle-dependencies


    【解决方案1】:

    如果您想要的是“生产”运行时依赖项,请使用 --configuration runtimeClasspath

    Gradle 中的配置就像依赖项的桶。 Java 插件贡献的那些被描述为here

    最有趣的是这些:

    • compileClasspath:编译项目所需的依赖项。扩展扩展 compile(已弃用)、compileOnlyimplementation
    • runtimeClasspath: 运行时需要的依赖。扩展 runtime(已弃用)、runtimeOnlyimplementation

    如您所见,上述两个版本还有用于编译和运行单元测试的“测试”版本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-08
      • 2020-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多