The standard way to extend a war artifact using Maven is to use Maven's Overlay Plugin.
Naturally, Gradle users wanted to adopt the same approach. And there are some solutions, including a gradle overlay plugin.
These all could be used. However, Gradle's powerful dependency management enables you to emulate the overlay plugin ad-hoc, and have a much more precise control on what you want to happen to your war.
Basically, what you need is to include a war as a non-transitive dependency, and copy all its contents to resulting war, preserving the changes you made.
apply plugin: 'war'
repositories {
mavenCentral()
}
configurations {
overlay {
transitive = false
}
}
dependencies {
overlay('your:dependency1:version')
overlay('your:dependency2:version')
}
war {
duplicatesStrategy = 'exclude'
configurations.overlay.filter({it.name.endsWith(".war")}).each {
from zipTree(it)
}
}
apply plugin: 'war'
repositories {
mavenCentral()
}
configurations {
overlay {
transitive = false
}
}
dependencies {
compile('org.problematic:problematic:newer_version')
overlay('your:dependency1:version')
overlay('your:dependency2:version')
}
war {
duplicatesStrategy = 'exclude'
webInf {
from "$projectDir/config"
}
configurations.overlay.filter({it.name.endsWith(".war") || it.name.endsWith(".zip")}).each {
from zipTree(it).matching { exclude '**/*problematic*.jar' }
}
}
apply plugin: 'war'
repositories {
mavenCentral()
}
configurations {
overlay
compile.extendsFrom(overlay)
}
dependencies {
overlay('your:dependency1:version')
overlay('your:dependency2:version')
}
war {
duplicatesStrategy = 'exclude'
configurations.overlay.filter({it.name.endsWith(".war") || it.name.endsWith(".zip")}).each {
from zipTree(it).matching { exclude '**/*.jar' }
}
}
Turn off your plugins, RTFM, and
use the force
of Gradle, Luke.