Standard jar task generates a jar with duplicate entries if we change the resource output folder


we change the default resource output folder with:

sourceSets.main.output.resourcesDir = sourceSets.main.output.classesDir

and we have the problem, that the generated jar file has everything dupicated. Class files and resources. And I saw that we can’t change the source property of the jar task because it’s read only. How can we achieve that the standard jar task of the java plugin creates a correct jar file?

Thanks in advance.


I can reproduce this with a basic Java project. I have created GRADLE-2213 for this. Here is a workaround:

sourceSets.main.output.resourcesDir = sourceSets.main.output.classesDir
jar.doFirst {
    sourceSets.main.output.resourcesDir = "/does/not/exist"
jar.doLast {
    sourceSets.main.output.resourcesDir = sourceSets.main.output.classesDir

I have to do this in multiple subprojects, some of which have different source sets (i.e. not main). Is there a way I can ‘decorate’ the appropriate jar tasks with workaround? Otherwise I have to copy/paste it in all my subprojects :frowning:

Also, I’m curious why exactly that works? It seems like the second call to main.output.resourcesDir should unset the first? I guess there’s something I don’t understand about the jar/resources lifecycle.