[GRADLE-1454] War task does not filter out non-unique items Created: 22/Mar/11 Updated: 08/Feb/17 Resolved: 08/Feb/17 |
|
Status: | Resolved |
Project: | Gradle |
Affects Version/s: | 1.0-milestone-1 |
Fix Version/s: | None |
Type: | Bug | ||
Reporter: | Sten Roger Sandvik | Assignee: | Unassigned |
Resolution: | Fixed | Votes: | 29 |
Attachments: | sample.zip |
Description |
It seems that the war task (and possibly other zip related tasks) does not filter out non-unique items. I have two projects: webapp1 and webapp2. Both using the war plugin and producing a war. Project webapp2 constructs the war using the following: war { with project(':webapp1').war }The resulting war includes duplicates. All files from webapp1 and all from webapp2. It does not filter out non-unique files. See attached zip for a build illustrating the bug. |
Comments |
Comment by Dewey [ 24/Mar/11 ] |
Having the same problem. When you go to unzip it, it'll try to overwrite the duplicate file with itself over again. |
Comment by Olivier Lefevre [ 13/Jul/11 ] |
The Jar and Zip tasks suffer from the same defect. |
Comment by Davide Cavestro [ 21/Sep/11 ] |
Having a web project that simply acts as a collector for some other web projects, I've merged them with no duplicates redefining the war task to use ant.zip with the duplicate attibute set to 'preserve'. apply plugin: 'war' jar.enabled = true dependsOn (':webprj1') dependsOn (':webprj2') def warPath = project.war.archivePath task war(overwrite: true) << { ant.zip(destfile: warPath, duplicate: 'preserve', keepcompression: true) { project.dependsOnProjects.each {prj-> zipfileset (src: prj.war.archivePath) } } } |
Comment by Michael Brand [ 08/Feb/12 ] |
I found this defect from the discussion http://gradle.1045684.n5.nabble.com/War-dependency-to-another-war-td4257270.html. The workaround mentioned in this thread is: war { into("/") { exclude 'META-INF/MANIFEST.MF' // or whatever with project(':common').war } } Unfortunately, I still get two MANIFEST.MF files using this code. Does anyone know a better workaround? |
Comment by Michael Brand [ 08/Feb/12 ] |
Here's what I came up with to insert the contents of one WAR into another, excluding duplicates: def warPath = project.war.archivePath war << { ant.zip(destfile: warPath, duplicate: 'preserve', keepcompression: true, update: true) { zipfileset (src: project(':common').war.archivePath) } } Thanks, Davide, for the example. Does anyone know of a better workaround? |
Comment by Ola Sundell [ 13/Dec/12 ] |
Since the war task extends the jar task which extends the zip task, I reckon this is similar to |
Comment by Daz DeBoer [ 06/Mar/13 ] |
If the problem is duplicate jar files in WEB-INF/lib, then the following might help: war { def originalClasspath = classpath // Restrict the classpath to files with unique names classpath = files { def uniqueFiles = [] originalClasspath.each { input -> if (uniqueFiles.find({it.name == input.name }) == null) { uniqueFiles << input } } return uniqueFiles } } |
Comment by Daz DeBoer [ 07/Mar/13 ] |
And a more solid plugin-based workaround: subprojects { apply plugin: WarTweaker } class WarTweaker implements Plugin<Project> { void apply(Project project) { project.tasks.withType(War) { task -> task.doFirst({ println "Removing duplicates from classpath of $task" def originalClasspath = task.classpath // Restrict the classpath to files with unique names task.classpath = project.files { def uniqueFiles = [] originalClasspath.each { input -> if (uniqueFiles.find({ it.name == input.name }) == null) { uniqueFiles << input } } return uniqueFiles } }) } } } |
Comment by Davide Cavestro [ 08/Mar/13 ] |
@Daz the plugin-based solution is very cool! |
Comment by Melody Dunn [ 20/Mar/13 ] |
the plugin doesn't get rid of the duplicate manifest file |
Comment by Thorsten Möller [ 18/Nov/13 ] |
Seemingly related to issues #710 and #934. |
Comment by Benjamin Muschko [ 15/Nov/16 ] |
As announced on the Gradle blog we are planning to completely migrate issues from JIRA to GitHub. We intend to prioritize issues that are actionable and impactful while working more closely with the community. Many of our JIRA issues are inactionable or irrelevant. We would like to request your help to ensure we can appropriately prioritize JIRA issues you’ve contributed to. Please confirm that you still advocate for your JIRA issue before December 10th, 2016 by:
We look forward to collaborating with you more closely on GitHub. Thank you for your contribution to Gradle! |
Comment by Benjamin Muschko [ 08/Feb/17 ] |
The use case should be solvable with AbstractCopyTask.setDuplicatesStrategy(DuplicatesStrategy). Please open an issue on GitHub in case you find that your use case still isn't fulfilled. |