I have a gradle project. There is a root Gradle folder with two subprojects - common and application.
| -common/
-build-gradle
| -application/
| -build.gradle
|build.gradle
|settings.gradle
Common
- Outputs a JAR file with all jar dependencies in it via ShadowJar
- Has only dependencies from Maven central repository, no other dependencies
Application
- Outputs WAR file
- Has Common's shadowJar as dependency.
- Has additional dependencies from Maven central repository
What I want to achieve
When I run gradle war on Application, I'd like to create a jar with all Maven dependencies in it, as well as Common project's ShadowJar.
Problem is with the ShadowJar part. When gradle war is executed on Application, no artifact is built in Common. I'd like to have shadowJar built and included into the war.
Current solution I added this into root's build.gradle
subprojects{
tasks.jar.enabled = false
artifacts{
shadowJar
}
build.dependsOn(shadowJar);
}
In Application/build.gradle, I have one more line
compile files('../common/build/libs/common.jar')
Then I run build task on root. Somehow, the common project is built first and the ShadowJar is included into the Application's WAR.
This is far from optimal. I'd like to have Application's dependency on Common defined as compile project(':common') rather than point to a fixed file name. However, the "compile project" statement obviously doesn't produce shadowJar in Common module and doesn't include it in the WAR in Application module.