Multiproject war build


(Anders Viskum) #1

Hi,

I’m trying to make a multiproject build and create a WAR file with all dependencies (both internal and external).

If I just use the war-plugin out of the box, the main project only gets the jar files from the subprojects - not the jar files from the subprojects external dependencies.

To achieve that I had to add something like the following:

war {

classpath project(’:services:personService’).configurations.default

classpath project(’:api’).configurations.default

classpath project(’:shared’).configurations.default }

…which seems like a hack.

Can anyone point me in the right direction?

See the full build.gradle below.

Kind regards Anders Viskum


apply plugin: ‘war’

subprojects {

apply plugin: ‘java’

group = ‘org.gradle.sample’

version = ‘1.0’

repositories {

mavenCentral()

}

dependencies {

compile “junit:junit:4.8.1”

} }

project(’:api’) {

dependencies {

compile project(’:shared’)

} }

project(’:services:personService’) {

dependencies {

compile project(’:shared’), project(’:api’)

} }

dependsOnChildren()

dependencies {

runtime project(’:services:personService’) }

war {

classpath project(’:services:personService’).configurations.default

classpath project(’:api’).configurations.default

classpath project(’:shared’).configurations.default }


(Adam Murdoch) #2

I think you’re hitting GRADLE-1398, as your root project does not have any repositories defined. You want something like:

allprojects { // note allprojects instead of subprojects
    mavenCentral()
}

then, your runtime dependencies should automatically end up in the war, and you can remove the explicit classpath definition for the war task.


(Anders Viskum) #3

Thanks a lot.

allprojects {

repositories {

mavenCentral()

}

}

did the trick…