我有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中重新制作另一个。
这可能吗?
你问的是传递依赖管理。
使用java-library
plugin时,Gradle支持开箱即用:
api
配置中的任何内容都可以传递给消费者的编译类路径,implementation
配置中的任何内容仅暴露给使用者的运行时类路径。现在,将模块编译所需的任何内容提升到第一级依赖项也被认为是最佳实践。这可以防止依赖性消失,如果传递它的模块不再这样做。
我不知道compileInclude
配置来自何处以及它如何参与模块公开或不公开的内容。
你应该不再使用compile
而是使用模块B中的implementation
。