similar to the post http://forums.gradle.org/gradle/topics/after_renaming_a_class_the_subsequently_created_jar_contains_both_versions_of_the_class I had this problem for quite some time, but stumbled upon it again with a new employee that did not know the trick to delete destinationDir in JavaCompile.doFirst.
Here is what we do:
the simplest java project with one Java Sourcefile in a package “test1”. build.gradle only contains “apply plugin: ‘java’”. I run “gradlew jar”. Then I rename the package “test1” to “test2” and also adapt the Java source file to reflect the changed package name A new “gradlew jar” results in a jar file that contains both “test1” and “test2” packages, with the classes inside.
We have had this problems for all the time we are using gradle now (about 2 years), and our standard workaround is
tasks.withType(JavaCompile)*.doFirst {
delete destinationDir
}
BTW: If I only rename the class and not the package, everything works as expected, only the new class is in build/classes and in the jar file. But as soon as I change the package name, I have both versions in the jar file.