4

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.

Pavel Pscheidl
  • 334
  • 3
  • 11
  • Why don't you simply build the war file of the application without using shadowJar at all? Gradle will put the common subproject as a small jar along with all its dependencies into libs. What is your motivation to have the `common` subproject as a fat jar in your war libs? – Andrey Vetlugin Apr 29 '19 at 16:29

0 Answers0