Skip to content

Commit

Permalink
Repackage annotation compiler dependencies to prevent conflicts
Browse files Browse the repository at this point in the history
Fixes #2059
  • Loading branch information
TWiStErRob authored and sjudd committed Sep 15, 2017
1 parent ec9f7a3 commit a0e388e
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 2 deletions.
85 changes: 83 additions & 2 deletions annotation/compiler/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import org.gradle.internal.jvm.Jvm
import java.nio.file.Files
import static java.nio.file.StandardCopyOption.*

apply plugin: 'java'

configurations {
// adapted from https://android.googlesource.com/platform/frameworks/testing/+/976c423/espresso/espresso-lib/build.gradle
// compileOnly dependencies will be repackaged, see rules in jarjar ant task below
jarjar
}

dependencies {
compile 'com.squareup:javapoet:1.9.0'
compile 'com.google.auto.service:auto-service:1.0-rc3'
// from https://code.google.com/archive/p/jarjar/downloads
jarjar files('libs/jarjar-1.4.jar')

compileOnly 'com.squareup:javapoet:1.9.0'
compileOnly 'com.google.auto.service:auto-service:1.0-rc3'

compile 'com.google.code.findbugs:jsr305:3.0.1'
compile project(':annotation')
// This is to support com.sun.tootls.javac.util.List, currently used in RootModuleGenerator.
Expand All @@ -14,4 +26,73 @@ dependencies {
testCompile 'com.google.testing.compile:compile-testing:0.10'
}

afterEvaluate {
// generate file names for each step
def resultingClassesJar = tasks.jar.archivePath
def originalClassifier = tasks.jar.classifier
tasks.jar.classifier = 'compiled'
def compiledClassesJar = tasks.jar.archivePath
tasks.jar.classifier = 'repackaged'
def repackagedClassesJar = tasks.jar.archivePath
tasks.jar.classifier = 'proguarded'
def proguardedClassesJar = tasks.jar.archivePath
tasks.jar.classifier = originalClassifier

tasks.jar.doLast {
Files.copy(resultingClassesJar.toPath(), compiledClassesJar.toPath(), REPLACE_EXISTING)
}
// Inject a jarjar task after jar into the assemble chain.
// afterEvaluate is needed to get the resolved version name for the jar artifact.
task jarjar(dependsOn: [tasks.jar, configurations.compileOnly]) {
tasks.assemble.dependsOn it

// Set up inputs and outputs to only rebuild when necessary (code change, dependency change).
inputs.file compiledClassesJar
inputs.files configurations.compileOnly
outputs.file repackagedClassesJar

doFirst {
ant {
taskdef name: 'jarjar',
classname: 'com.tonicsystems.jarjar.JarJarTask',
classpath: configurations.jarjar.asPath
// Generate the original JAR output where it was originally expected.
jarjar(jarfile: repackagedClassesJar) {
configurations.compileOnly.resolve().each {
zipfileset(src: it.absolutePath, excludes: [
'META-INF/maven/**',
'META-INF/services/javax.annotation.processing.Processor'
].join(','))
}
zipfileset(src: tasks.jar.archivePath)
def repackageIntoGlide = 'com.bumptech.glide.repackaged.@0'
rule result: repackageIntoGlide, pattern: 'com.squareup.javapoet.**'
rule result: repackageIntoGlide, pattern: 'com.google.auto.**'
rule result: repackageIntoGlide, pattern: 'com.google.common.**'
rule result: repackageIntoGlide, pattern: 'com.google.thirdparty.publicsuffix.**'
}
}
}

doLast {
Files.copy(repackagedClassesJar.toPath(), resultingClassesJar.toPath(), REPLACE_EXISTING)
}
}

task proguard(type: proguard.gradle.ProGuardTask, dependsOn: tasks.jarjar) {
tasks.assemble.dependsOn it
configuration 'proguard.pro'

injars repackagedClassesJar
outjars proguardedClassesJar

libraryjars files(configurations.compile.collect())
libraryjars "${System.getProperty('java.home')}/lib/rt.jar"

doLast {
Files.copy(proguardedClassesJar.toPath(), resultingClassesJar.toPath(), REPLACE_EXISTING)
}
}
}

apply from: "${rootProject.projectDir}/scripts/upload.gradle"
Binary file added annotation/compiler/libs/jarjar-1.4.jar
Binary file not shown.
22 changes: 22 additions & 0 deletions annotation/compiler/proguard.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-verbose
# Use ProGuard only to get rid of unused classes
-dontobfuscate
-dontoptimize
-keepattributes *
-keep class !com.bumptech.glide.repackaged.**,com.bumptech.glide.**

# Keep the entry point to this library, see META-INF\services\javax.annotation.processing.Processor
-keep class com.bumptech.glide.annotation.compiler.GlideAnnotationProcessor


# "duplicate definition of library class"
-dontnote sun.applet.**
# "duplicate definition of library class"
-dontnote sun.tools.jar.**
# Reflective accesses in com.google.common.util.concurrent.* and some others
-dontnote com.bumptech.glide.repackaged.com.google.common.**
# com.google.common.collect.* and some others (….common.*.*)
-dontwarn com.google.j2objc.annotations.Weak
# com.google.common.util.concurrent.FuturesGetChecked$GetCheckedTypeValidatorHolder$ClassValueValidator
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
#-dontwarn **

0 comments on commit a0e388e

Please sign in to comment.