Skip to content

Commit 7c09fc1

Browse files
committed
Avoid including default source sets in repackaged compiler jar.
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.
1 parent 7614e10 commit 7c09fc1

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

annotation/compiler/build.gradle

+8-1
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,17 @@ task proguard(type: ProGuardTask, dependsOn: tasks.jarjar) {
7474
libraryjars "${System.getProperty('java.home')}/lib/rt.jar"
7575
}
7676

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

8390
apply from: "${rootProject.projectDir}/scripts/upload.gradle"

build.gradle

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ subprojects {
2626
sourceCompatibility = 1.7
2727
targetCompatibility = 1.7
2828
}
29+
30+
// Avoid issues like #2452.
31+
tasks.withType(Jar) {
32+
duplicatesStrategy = DuplicatesStrategy.FAIL
33+
}
2934
}
3035

3136
subprojects { project ->

0 commit comments

Comments
 (0)