Skip to content

Commit

Permalink
Update Glide to Gradle 7+
Browse files Browse the repository at this point in the history
This change will require newer versions of Java, probably 9+. I've
tested it on 11. The biggest difference is that older versions of Java
will require rt.jar to compile Glide's annotation processor. On newer
versions of Java that jar has been removed and the dependencies are
available as part of the Java plugin. For now I've required newer
versions of Java. If this proves complex, we could optionally include
rt.jar and partially revert this change when we detect older versions of
Java being used.

The single largest problem with this change is that I cannot figure out
a way to get the annotation processor tests to run. They require the
android library plugin because they depend directly on Android code.
However, they also require access to javax classes. These classes are
included via jmods on newer versions of Java and the rt jar is not
available. The jmods are only available from the Java plugin, not the
android plugin. This means that we can either get access to the android
classes, or the javax classes, but not both. I can't find a reasonable
way to resolve this in the short term. For now the tests are still
enabled using blaze/bazel internally.
  • Loading branch information
sjudd committed Jun 27, 2022
1 parent fd5e7df commit fdbb694
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 132 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '1.8'
java-version: '11'
distribution: 'zulu'
- name: Build and run unit tests with Gradle
run: ./scripts/ci_unit.sh
- name: Publish to Sonatype
Expand Down
7 changes: 6 additions & 1 deletion annotation/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
apply plugin: 'java'

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

java {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
33 changes: 23 additions & 10 deletions annotation/compiler/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import org.gradle.internal.jvm.Jvm
import proguard.gradle.ProGuardTask

apply plugin: 'java'
Expand All @@ -16,14 +15,17 @@ dependencies {
compileOnly "com.squareup:javapoet:${JAVAPOET_VERSION}"
compileOnly "com.google.auto.service:auto-service:${AUTO_SERVICE_VERSION}"
compileOnly "com.google.code.findbugs:jsr305:${JSR_305_VERSION}"
compile project(':annotation')
// This is to support com.sun.tools.javac.util.List, currently used in RootModuleGenerator.
compile files(Jvm.current().getToolsJar())
implementation project(':annotation')
annotationProcessor "com.google.auto.service:auto-service:${AUTO_SERVICE_VERSION}"
}

javadoc {
failOnError = false
}

// TODO: Figure out a way to get the annotation processor tests running and re-enable this.
// Make sure running `gradlew :annotation:compiler:check` actually does full quality control.
test.dependsOn ':annotation:compiler:test:test'
//test.dependsOn ':annotation:compiler:test:test'

def packagingFolder = file("${buildDir}/intermediates")
def repackagedJar = file("${packagingFolder}/repackaged.jar")
Expand All @@ -36,10 +38,10 @@ task compiledJar(type: Jar, dependsOn: classes) {
}

// Repackage compileOnly dependencies to avoid namespace collisions.
task jarjar(dependsOn: [tasks.compiledJar, configurations.compileOnly]) {
task jarjar(dependsOn: [tasks.compiledJar, configurations.compileClasspath]) {
// Set up inputs and outputs to only rebuild when necessary (code change, dependency change).
inputs.files compiledJar
inputs.files configurations.compileOnly
inputs.files configurations.compileClasspath
outputs.file repackagedJar

doFirst {
Expand All @@ -49,7 +51,7 @@ task jarjar(dependsOn: [tasks.compiledJar, configurations.compileOnly]) {
classpath: configurations.jarjar.asPath

jarjar(jarfile: repackagedJar) {
configurations.compileOnly.resolve().each {
configurations.compileClasspath.resolve().each {
zipfileset(src: it.absolutePath, excludes: [
'META-INF/maven/**',
'META-INF/services/javax.annotation.processing.Processor'
Expand All @@ -73,8 +75,19 @@ task proguard(type: ProGuardTask, dependsOn: tasks.jarjar) {
injars repackagedJar
outjars proguardedJar

libraryjars files(configurations.compile.collect())
libraryjars "${System.getProperty('java.home')}/lib/rt.jar"
libraryjars files(configurations.compileClasspath.collect())
// From http://cr.openjdk.java.net/~mr/jigsaw/ea/module-summary.html
for (jmod in [
"java.base",
"java.logging",
"java.compiler",
"jdk.compiler",
"jdk.unsupported"]) {
libraryjars(
"${System.getProperty('java.home')}/jmods/${jmod}.jmod",
jarfilter: '!**.jar',
filter: '!module-info.class')
}
}

// Replace the contents of the standard jar task with those from our our compiled, repackaged and
Expand Down
6 changes: 2 additions & 4 deletions annotation/compiler/test/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.gradle.internal.jvm.Jvm

apply plugin: 'com.android.library'

android {
Expand Down Expand Up @@ -72,8 +70,8 @@ dependencies {
}
testImplementation "androidx.annotation:annotation:${ANDROID_X_ANNOTATION_VERSION}"
testImplementation "androidx.fragment:fragment:${ANDROID_X_FRAGMENT_VERSION}"
// TODO: this seems excessive, but it works...
testImplementation files(Jvm.current().getJre().homeDir.getAbsolutePath()+'/lib/rt.jar')
// TODO: Find some way to include a similar dependency on java 9+ and re-enable these tests in gradle.
// testImplementation files(Jvm.current().getJre().homeDir.getAbsolutePath()+'/lib/rt.jar')

testAnnotationProcessor project(':annotation:compiler')
testAnnotationProcessor "com.google.auto.service:auto-service:${AUTO_SERVICE_VERSION}"
Expand Down
7 changes: 2 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ buildscript {
if (!hasProperty('DISABLE_ERROR_PRONE')) {
classpath "net.ltgt.gradle:gradle-errorprone-plugin:${ERROR_PRONE_PLUGIN_VERSION}"
}
classpath 'com.guardsquare:proguard-gradle:7.1.0'
classpath "se.bjurr.violations:violations-gradle-plugin:${VIOLATIONS_PLUGIN_VERSION}"
classpath "androidx.benchmark:benchmark-gradle-plugin:${ANDROID_X_BENCHMARK_VERSION}"
}
Expand Down Expand Up @@ -45,7 +46,6 @@ subprojects { project ->
sourceCompatibility = 1.7
targetCompatibility = 1.7

options.setBootstrapClasspath(files("${System.getProperty('java.home')}/lib/rt.jar"))
// gifencoder is a legacy project that has a ton of warnings and is basically never
// modified, so we're not going to worry about cleaning it up.
// Imgur uses generated code from dagger that has warnings.
Expand Down Expand Up @@ -74,10 +74,7 @@ subprojects { project ->
*/ \
<< "-Xlint:-deprecation"

if (project.plugins.hasPlugin('net.ltgt.errorprone')) {
// It's often useful to track individual objects when debugging object pooling.
options.compilerArgs << "-Xep:ObjectToString:OFF"
}

}
}

Expand Down
3 changes: 1 addition & 2 deletions glide/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ def javadocTask = tasks.create("debugJavadoc", Javadoc) {
links("http://docs.oracle.com/javase/7/docs/api/")
links("https://square.github.io/okhttp/3.x/okhttp/")
links("https://square.github.io/okhttp/2.x/okhttp/")
linksOffline("http://d.android.com/reference",
"${getAndroidSdkDirectory()}/docs/reference")
links("http://d.android.com/reference")
}

exclude '**/R.java'
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ ANDROID_X_TRACING_VERSION=1.0.0
ANDROID_X_VECTOR_DRAWABLE_ANIMATED_VERSION=1.0.0

## Other dependency versions
ANDROID_GRADLE_VERSION=4.1.0
ANDROID_GRADLE_VERSION=7.2.1
AUTO_SERVICE_VERSION=1.0-rc3
DAGGER_VERSION=2.15
ERROR_PRONE_PLUGIN_VERSION=0.0.13
ERROR_PRONE_VERSION=2.3.1
ERROR_PRONE_PLUGIN_VERSION=2.0.2
ERROR_PRONE_VERSION=2.3.4
GUAVA_TESTLIB_VERSION=18.0
GUAVA_VERSION=28.1-android
JAVAPOET_VERSION=1.9.0
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
19 changes: 18 additions & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ dependencies {
testImplementation "androidx.test:runner:${ANDROID_X_TEST_RUNNER_VERSION}"
}

if (project.plugins.hasPlugin('net.ltgt.errorprone')) {
tasks.withType(JavaCompile) {
options.errorprone.disable(
// It's often useful to track individual objects when debugging
// object pooling.
"ObjectToString",
// Doesn't apply when we can't use lambadas.
"UnnecessaryAnonymousClass",
// TODO(judds): Fix these and re-enable this check
"TypeNameShadowing",
"UndefinedEquals",
"UnnecessaryParentheses",
"UnusedVariable",
"EqualsGetClass",
"LockNotBeforeTry")
}
}

android {
compileSdkVersion COMPILE_SDK_VERSION as int

Expand All @@ -59,7 +77,6 @@ check.dependsOn(':library:test:check')
def classPathForQuality() {
return files(
android.bootClasspath,
project.configurations.compile,
project.android.libraryVariants.collect { it.javaCompile.classpath }
)
}
Expand Down
Loading

0 comments on commit fdbb694

Please sign in to comment.