提交 a0e388e2 编写于 作者: R Robert Papp 提交者: Sam Judd

Repackage annotation compiler dependencies to prevent conflicts

Fixes #2059
上级 ec9f7a32
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.
......@@ -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"
-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 **
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册