【问题标题】:How to include a module's jar as a dependency in another module in Gradle?如何将模块的 jar 作为依赖项包含在 Gradle 中的另一个模块中?
【发布时间】:2019-02-25 14:58:33
【问题描述】:

我有 2 个模块,我们称它们为 A、B。

模块 A .gradle 是

dependencies {
    compileInclude group: "Service1", name: "Service1", version: "$rootProject.ext.Service1"
    compileInclude group: "Service2", name: "Service2", version: "$rootProject.ext.Service2"
    compileInclude group: "Service3", name: "Service3", version: "$rootProject.ext.Service3"
}

模块 B .gradle 是

dependencies {
    compileOnly project(":modules:ModuleA")
}

我想在模块B中使用模块A的Service1.Jar,而不必在模块B中重新制作另一个。

这可能吗?

【问题讨论】:

    标签: gradle liferay-7


    【解决方案1】:

    你问的是传递依赖管理。

    Gradle 在使用 java-library plugin 时支持开箱即用:

    • api 配置中的任何内容都会传递给消费者的 compile 类路径,
    • implementation 配置中的任何内容都只会暴露给消费者的 runtime 类路径。

    现在,将模块编译所需的任何内容提升到一级依赖项也被认为是最佳实践。如果传递它的模块不再这样做,这可以防止依赖关系消失。

    但我不知道compileInclude 配置的来源以及它如何参与模块公开的内容。

    并且您不应再在模块 B 中使用 compile 而是使用 implementation

    【讨论】:

      猜你喜欢
      • 2018-03-13
      • 1970-01-01
      • 1970-01-01
      • 2017-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-26
      • 2013-05-08
      相关资源
      最近更新 更多