Skip to content

Commit a0e388e

Browse files
TWiStErRobsjudd
authored andcommitted
Repackage annotation compiler dependencies to prevent conflicts
Fixes bumptech#2059
1 parent ec9f7a3 commit a0e388e

File tree

3 files changed

+105
-2
lines changed

3 files changed

+105
-2
lines changed

annotation/compiler/build.gradle

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
import org.gradle.internal.jvm.Jvm
2+
import java.nio.file.Files
3+
import static java.nio.file.StandardCopyOption.*
24

35
apply plugin: 'java'
46

7+
configurations {
8+
// adapted from https://android.googlesource.com/platform/frameworks/testing/+/976c423/espresso/espresso-lib/build.gradle
9+
// compileOnly dependencies will be repackaged, see rules in jarjar ant task below
10+
jarjar
11+
}
12+
513
dependencies {
6-
compile 'com.squareup:javapoet:1.9.0'
7-
compile 'com.google.auto.service:auto-service:1.0-rc3'
14+
// from https://code.google.com/archive/p/jarjar/downloads
15+
jarjar files('libs/jarjar-1.4.jar')
16+
17+
compileOnly 'com.squareup:javapoet:1.9.0'
18+
compileOnly 'com.google.auto.service:auto-service:1.0-rc3'
19+
820
compile 'com.google.code.findbugs:jsr305:3.0.1'
921
compile project(':annotation')
1022
// This is to support com.sun.tootls.javac.util.List, currently used in RootModuleGenerator.
@@ -14,4 +26,73 @@ dependencies {
1426
testCompile 'com.google.testing.compile:compile-testing:0.10'
1527
}
1628

29+
afterEvaluate {
30+
// generate file names for each step
31+
def resultingClassesJar = tasks.jar.archivePath
32+
def originalClassifier = tasks.jar.classifier
33+
tasks.jar.classifier = 'compiled'
34+
def compiledClassesJar = tasks.jar.archivePath
35+
tasks.jar.classifier = 'repackaged'
36+
def repackagedClassesJar = tasks.jar.archivePath
37+
tasks.jar.classifier = 'proguarded'
38+
def proguardedClassesJar = tasks.jar.archivePath
39+
tasks.jar.classifier = originalClassifier
40+
41+
tasks.jar.doLast {
42+
Files.copy(resultingClassesJar.toPath(), compiledClassesJar.toPath(), REPLACE_EXISTING)
43+
}
44+
// Inject a jarjar task after jar into the assemble chain.
45+
// afterEvaluate is needed to get the resolved version name for the jar artifact.
46+
task jarjar(dependsOn: [tasks.jar, configurations.compileOnly]) {
47+
tasks.assemble.dependsOn it
48+
49+
// Set up inputs and outputs to only rebuild when necessary (code change, dependency change).
50+
inputs.file compiledClassesJar
51+
inputs.files configurations.compileOnly
52+
outputs.file repackagedClassesJar
53+
54+
doFirst {
55+
ant {
56+
taskdef name: 'jarjar',
57+
classname: 'com.tonicsystems.jarjar.JarJarTask',
58+
classpath: configurations.jarjar.asPath
59+
// Generate the original JAR output where it was originally expected.
60+
jarjar(jarfile: repackagedClassesJar) {
61+
configurations.compileOnly.resolve().each {
62+
zipfileset(src: it.absolutePath, excludes: [
63+
'META-INF/maven/**',
64+
'META-INF/services/javax.annotation.processing.Processor'
65+
].join(','))
66+
}
67+
zipfileset(src: tasks.jar.archivePath)
68+
def repackageIntoGlide = 'com.bumptech.glide.repackaged.@0'
69+
rule result: repackageIntoGlide, pattern: 'com.squareup.javapoet.**'
70+
rule result: repackageIntoGlide, pattern: 'com.google.auto.**'
71+
rule result: repackageIntoGlide, pattern: 'com.google.common.**'
72+
rule result: repackageIntoGlide, pattern: 'com.google.thirdparty.publicsuffix.**'
73+
}
74+
}
75+
}
76+
77+
doLast {
78+
Files.copy(repackagedClassesJar.toPath(), resultingClassesJar.toPath(), REPLACE_EXISTING)
79+
}
80+
}
81+
82+
task proguard(type: proguard.gradle.ProGuardTask, dependsOn: tasks.jarjar) {
83+
tasks.assemble.dependsOn it
84+
configuration 'proguard.pro'
85+
86+
injars repackagedClassesJar
87+
outjars proguardedClassesJar
88+
89+
libraryjars files(configurations.compile.collect())
90+
libraryjars "${System.getProperty('java.home')}/lib/rt.jar"
91+
92+
doLast {
93+
Files.copy(proguardedClassesJar.toPath(), resultingClassesJar.toPath(), REPLACE_EXISTING)
94+
}
95+
}
96+
}
97+
1798
apply from: "${rootProject.projectDir}/scripts/upload.gradle"
118 KB
Binary file not shown.

annotation/compiler/proguard.pro

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-verbose
2+
# Use ProGuard only to get rid of unused classes
3+
-dontobfuscate
4+
-dontoptimize
5+
-keepattributes *
6+
-keep class !com.bumptech.glide.repackaged.**,com.bumptech.glide.**
7+
8+
# Keep the entry point to this library, see META-INF\services\javax.annotation.processing.Processor
9+
-keep class com.bumptech.glide.annotation.compiler.GlideAnnotationProcessor
10+
11+
12+
# "duplicate definition of library class"
13+
-dontnote sun.applet.**
14+
# "duplicate definition of library class"
15+
-dontnote sun.tools.jar.**
16+
# Reflective accesses in com.google.common.util.concurrent.* and some others
17+
-dontnote com.bumptech.glide.repackaged.com.google.common.**
18+
# com.google.common.collect.* and some others (….common.*.*)
19+
-dontwarn com.google.j2objc.annotations.Weak
20+
# com.google.common.util.concurrent.FuturesGetChecked$GetCheckedTypeValidatorHolder$ClassValueValidator
21+
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
22+
#-dontwarn **

0 commit comments

Comments
 (0)