War has duplicate jars

I have a standard war build in eclipse, and I’m trying to use gradle to build the war. When I do so, the war is built correctly, expect, that in the zip structure, the libs directory is duplicated 2 times, and this is apparent, when you unzip the file, into an empty directory, half way through, using 7zip, it prompts you to overwrite .jar files. also, if you unzip the war, and rezip it, the file shrinks by the size of the libs directory. attached is the build script,

apply plugin: ‘war’

project.ext.set(“springVersion”,“3.0.3.RELEASE”); //sourceCompatibility = 1.6 //slf4jVersion = “1.6.1”

group = ‘com.fti’ version = ‘1.0’ description=“mms”

webAppDirName = ‘WebRoot’

repositories {

mavenCentral() }


compile fileTree(dir:‘WebRoot/WEB-INF/lib’, include:’*.jar’)

compile “javax.servlet:servlet-api:2.5” }

sourceSets {

main {

java { srcDir ‘src/’ }

resources { srcDir ‘src/’ }

} }

war { }

Hi Michael,

It’s because you have the compile dependency listed as the JARs that are in the WebRoot/WEB-INF/lib dir, and your war {…} closure is empty. By default, the war plugin includes what’s in the WEB-INF/lib directory in the WAR package, and anything that’s on the compile configuration.

You can probably avoid the duplicates by specifying providedCompile instead of compile for that one dependency. If that doesn’t work, maybe specifying the webAppDir setting per:


Specifically about the webAppDir convention setting.

Hope that helps!

provideCompile was the solution. Thanks

I have this problem with duplicate jars too.

My main web project has the libraries needed in WEB-INF/lib, and it has source files in it which depend on it. But then there some other projects, which have compile dependencies to these jars in WEB-INF/lib, and they a listed as dependencies of the web project.

So, what do I have to do to NOT include the compile dependencies of these dependent projects, which leads to these duplicate jars in the war??? I’ve tried to make the dependencies of the web project’s classes as ‘providedCompile’; but this does not have the effect.

ok, over the weekend i found this : http://gradle.1045684.n5.nabble.com/War-packed-with-duplicated-jars-td4624905.html, which was an exact match on my problem.

      exclude 'WEB-INF/lib/*'