如何在Gradle的另一个模块中包含模块的jar作为依赖项?

问题描述 投票:0回答:1

我有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个回答
0
投票

你问的是传递依赖管理。

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

  • 放置在api配置中的任何内容都可以传递给消费者的编译类路径,
  • 放置在implementation配置中的任何内容仅暴露给使用者的运行时类路径。

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

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

你应该不再使用compile而是使用模块B中的implementation

© www.soinside.com 2019 - 2024. All rights reserved.