After hours of researching and trying I hope that someone can explain how we can have Gradle including classes of one or more subproject into a specific jar.
经过几个小时的研究和尝试,我希望有人可以解释我们如何让Gradle包括一个或多个子项目的类到特定的jar中。
Lets say we have just three modules
让我们说我们只有三个模块
- Core
- 核心
- App
- 应用
- Web
- 卷筒纸
Obviously the App
and Web
project artifacts (jars) should contain all classes from the Core
project.
显然,App和Web项目工件(jar)应该包含Core项目中的所有类。
Settings gradle:
设置gradle:
rootProject.name = 'MyProject'
include 'MyProjectCore'
include 'MyProjectApp'
include 'MyProjectWeb'
MyProjectApp / MyProjectWeb:
MyProjectApp / MyProjectWeb:
...
dependencies {
...
compile project(':MyProjectCore')
}
The projects can be compiled but the output jars do not contain the core classes.
可以编译项目,但输出jar不包含核心类。
1 个解决方案
#1
3
Okay finally I found a working solution even if it might not be the best.
好吧,最后我找到了一个可行的解决方案,即使它可能不是最好的。
For the App
and Web
projects I overwrite the jar
task like this to add the source sets of the Core
module.
对于App和Web项目,我覆盖了这样的jar任务,以添加Core模块的源集。
jar {
from project.sourceSets.main.allSource
from project(":MyProjectCore").sourceSets.main.java.srcDirs
}
#1
3
Okay finally I found a working solution even if it might not be the best.
好吧,最后我找到了一个可行的解决方案,即使它可能不是最好的。
For the App
and Web
projects I overwrite the jar
task like this to add the source sets of the Core
module.
对于App和Web项目,我覆盖了这样的jar任务,以添加Core模块的源集。
jar {
from project.sourceSets.main.allSource
from project(":MyProjectCore").sourceSets.main.java.srcDirs
}