I have a fairly simple requirement. I have the following project layout:
project/build.gradle
--src/main/java
--src/main/res
What I would like to do is create a jar for all the java files in project/src/main/java
Include this jar file in the war and then exclude the WEB-INF/classes from the war file
build.gradle look as follows:apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'jetty'
apply plugin: 'war'
dependencies {
..
compile 'com.fasterxml.jackson.core:jackson-core:2.3.0'
compile 'com.fasterxml.jackson.core:jackson-databind:2.3.0'
..
}
jar {
archiveName = 'hello.jar'
}
war {
dependsOn jar
archiveName = 'hello.war'
classpath fileTree(dir:'build/libs/',include:'*.jar')
classpath configurations.compile
webInf {
from ('src/main/res') {
include '**/*.*'
into 'resources/'
}
}
}
I have tried various things to exclude WEB-INF/classes including the following snippets:
Using rootSpec.exclude:
war {
dependsOn jar
archiveName = 'hello.war'
classpath fileTree(dir:'build/libs/',include:'*.jar')
classpath configurations.compile
rootSpec.exclude ('WEB-INF/classes')
...
}
Using classpath:
war {
dependsOn jar
archiveName = 'hello.war'
classpath fileTree(dir:'build/libs/',include:'*.jar')
classpath configurations.compile
classpath fileTree(dir:'build/classes/', exclude:'*.class')
...
}
Using from ('war'):
war {
dependsOn jar
archiveName = 'hello.war'
classpath fileTree(dir:'build/libs/',include:'*.jar')
classpath configurations.compile
from ('war') {
exclude('WEB-INF/classes')
}
}
Doing a direct 'exclude':
war {
dependsOn jar
archiveName = 'hello.war'
classpath fileTree(dir:'build/libs/',include:'*.jar')
classpath configurations.compile
exclude('WEB-INF/classes')
...
}
Which were all the suggestions I found online - but none of them seems to work. Any ideas what I am doing wrong.
Here are links to some of the articles and code I found: Gradle: War Task has Conflicting Includes/Excludes
How to Exclude directory and its contents in gradle war
https://github.com/veny/smevente/blob/master/build.gradle
https://discuss.gradle.org/t/how-can-i-exlude-files-from-war-when-using-war-plugin-against-default-or-webappdirname-location/7366/6
The gradle version is 2.12.
Below is what worked for me, but you will still see an (harmless) empty package in the war bundle:
war {
rootSpec.exclude('**/com/xxxxx/web/client/')
}
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