【发布时间】:2020-09-18 17:20:19
【问题描述】:
我有一个具有以下结构的 Java 项目的多模块设置。
mainApp
|--> core-module
| |--> src
| |--> build.gradle
|--> implementation group: 'org.apache.axis2', name: 'axis2-kernel', version: '1.7.8'
|--> implementation group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.13'
|--> implementation files('libs/some_local.jar')
|--> compile project(":lib-module")
|--> compile project(":lib-another-module")
|--> ...
|
|--> lib-module
| |--> src
| |--> build.gradle
|--> implementation group: 'commons-lang', name: 'commons-lang', version: '2.6'
|--> implementation files('libs/another_local.jar')
|--> ...
|--> lib-another-module
| |--> src
| |--> build.gradle
|--> implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
|--> implementation files('libs/another_local.jar')
|--> ...
|
|--> settings.gradle
|--> build.gradle
|--> gradle.properties
在mainApp/build.gradle 文件中,我有一个“提及”的子模块
sourceSets {
main {
java {
srcDirs project('core-module').file("src")
srcDirs project('lib-module').file("src")
srcDirs project('lib-another-module').file("src")
}
}
}
如果我构建单个子模块,它会成功编译,但是当我在 root 运行 ./gradlew compileJava 时,它会因来自我已经在子模块中提到的 jar 中的 classNotFoundExceptions 而失败
> Task :core-module:compileJava
//successful
> Task :lib-module:compileJava
//successful
> Task :lib-another-module:compileJava
//successful
> Task :compileJava
/.../core-module/src/java/../OAuthUtils.java:12: error: package org.apache.http does not exist
import org.apache.http.Header;
...
//FAILED!
这里./gradlew core-module:compileJava 可以完美运行,但是从 root 调用时编译失败。
- 我该如何处理?
- 是因为文件系统引用了一些本地 jars 吗?
编辑
我发现根sourceSets{}指向子sub-module的编译失败,个别sub-module编译成功。
但是,我需要这个 sourceSets{} 来创建所有 sub-module 的一个整体罐子
注意:-我不是在这里创建fatJar 或shadedJar,但我需要包含来自所有sub-modules 的所有包,而不需要依赖jar。
【问题讨论】:
-
希望对你有帮助 -> stackoverflow.com/questions/50106128/…
-
在我的情况下完全相反。我的
dependencies对于不同的模块是不同的。因此,我不能把它集中在parent模块中。其次,我的个人子模块> Task :core-module:compileJava正在编译,但作为一个整体项目编译失败,这有点奇怪? -
在
sub-module中添加了jar { enabled = true },但没有运气。 -
对不起,我的错。我不是在这里创建
fatJar或shadedJar,但我需要包含来自所有sub-modules的包
标签: java spring hibernate gradle build.gradle