//below is redundant because the java plugin does it automatically
jar {
from project.sourceSets.main.output
}
//below does not make much sense because java plugin already puts the output in the jar
//adding a new 'from' folder causes the duplicates
jar {
from project.sourceSets.main.output.classesDir
}
//below means exactly the same as the 1st
jar {
from(project.sourceSets.main.output) {}
}
Hope that helps. If in doubts, please read the chapter about the java plugin in the user guide
In fact, the jar plugin has a bug: if ‘sourceSets.output.main.{classes,resources}Dir’ are the same, it will happily create a jar will all files added twice, without noticing the fact that they are in fact the same path.
I noticed the problem very recently while working on a pull request to the gradle-fatjar-plugin. And I think gradle should do the same here: when collecting files, it should take each file’s canonical path and add it to a ‘Set’.
Gradle 1.7 adds the ability to control how duplicates are dealt with when creating archives.
Trying to unique the files as you suggest won’t quite work. While they are the same source file, there’s nothing stopping one of the tasks (compile or processResources) transforming them in some way.
It might be better to merge identical entries when merging, which will be another kind of duplicates strategy.