War plugin does not use correct war.xml file in Gradle 1.7

In our web project, we have two web.xml files, one for eclipse development and one for production. In our build script we specify that the production build shall have a specific file. This worked fine for Gradle 1.5 but after upgrade to Gradle 1.7 it does not work anymore.

Under WEB-INF, there are two files: web.xml and web-prod.xml Our specification points out the production version: war {

webXml = file(‘src/main/webapp/WEB-INF/web-prod.xml’) }

According to war plugin documentation, there are no changes.

The War task extends from AbstractCopyTask, and the way CopySpec’s work has changed in Gradle 1.7.

I’m guessing that your src/main/webapp/WEB-INF directory contains both web.xml and web-prod.xml.

By default the war task will include everything under src/main/webapp (which will pull in both web.xml and web-prod.xml under the WEB-INF directory).

Assuming I’m correct in these assumptions, when I run under Gradle 1.5 there are two instances of web.xml in the resulting war file. This is also true with Gradle 1.7 but the order is different.

In Gradle 1.5 the web.xml file that corresponds to the contents of web-prod.xml is the last instance include in the war file, so that is the one used at runtime. In Gradle 1.7, it’s reversed, so that the original web.xml is the second copy of that file in the war, which is not what you want.

The duplicate copy of a file named web.xml in the resulting war is the main issue, and there are at least two ways to go about dealing with this:

[1] Keep web.xml and web-prod.xml in some other directory that isn’t src/main/webapp/WEB-INF and then explicitly point to each file as webXml for development/production (might cause you eclipse development issues though).

[2] In Gradle 1.7 you can tell gradle copy tasks to exclude duplicates, which at least right now gets the version that you need since the webXml file is added to the zip bundle before contents of the src/main/webapps are added (and the default web.xml file gets excluded).

war {
  setDuplicatesStrategy("EXCLUDE")
}

or

war {
  duplicatesStrategy = "EXCLUDE"
}

-Spencer