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.
Lets say we have just three modules
Obviously the App
and Web
project artifacts (jars) should contain all classes from the Core
project.
Settings gradle:
rootProject.name = 'MyProject'
include 'MyProjectCore'
include 'MyProjectApp'
include 'MyProjectWeb'
MyProjectApp / MyProjectWeb:
...
dependencies {
...
compile project(':MyProjectCore')
}
The projects can be compiled but the output jars do not contain the core classes.
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.
jar {
from project.sourceSets.main.allSource
from project(":MyProjectCore").sourceSets.main.java.srcDirs
}
With this you can add all *.class files created in your subprojects into your jar automatically:
jar {
from {
subprojects.collect { it.sourceSets.main.output }
}
}
To make sure the .class are there, make sure the root project depends on the subprojects:
dependencies {
compile project(':mySubProject')
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With