Skip to content

Commit

Permalink
Avoid including default source sets in repackaged compiler jar.
Browse files Browse the repository at this point in the history
Unless you override the jar task completely, any files you specified are
added to the original files, not replaced. To make matters worse, gradle
does not fail jar tasks when duplicate classes are added by default.

We’ve fixed the immediate issue with compiler’s jar file by excluding classes that do not originate from our repackaged/proguarded jar to 
avoid duplicate class files.We’ve hopefully also prevented future occurrences by forcing all jar tasks in the project to fail by default 
if duplicate classes are added.

Fixes #2452.
  • Loading branch information
sjudd committed Oct 8, 2017
1 parent 7614e10 commit 7c09fc1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion annotation/compiler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,17 @@ task proguard(type: ProGuardTask, dependsOn: tasks.jarjar) {
libraryjars "${System.getProperty('java.home')}/lib/rt.jar"
}

// Create the standard jar artifact based on our compiled, repackaged and proguarded jar.
// Replace the contents of the standard jar task with those from our our compiled, repackaged and
// proguarded jar. Replacing the task itself is possible and looks simpler, but requires
// reconstructing the task dependency chain and is more complex in practice.
jar {
dependsOn proguard
from zipTree(proguardedJar)
exclude { entry ->
sourceSets.main.output.files*.absolutePath.any {
entry.file.absolutePath.startsWith it
}
}
}

apply from: "${rootProject.projectDir}/scripts/upload.gradle"
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ subprojects {
sourceCompatibility = 1.7
targetCompatibility = 1.7
}

// Avoid issues like #2452.
tasks.withType(Jar) {
duplicatesStrategy = DuplicatesStrategy.FAIL
}
}

subprojects { project ->
Expand Down

0 comments on commit 7c09fc1

Please sign in to comment.