From f5ac706d9c6b6fc9546109b329ef2c4543aeed1a Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Fri, 4 Feb 2022 10:08:02 -0800 Subject: [PATCH] Get Android sample apps building on JDK 11 (#531) Update to AGP 7, so now the full NullAway build runs on JDK 11. The sample apps no longer build on JDK 8. --- .github/workflows/continuous-integration.yml | 2 +- build.gradle | 11 +++++++++-- gradle/dependencies.gradle | 1 - jar-infer/jar-infer-lib/build.gradle | 4 +++- .../com/uber/nullaway/jarinfer/JarInferTest.java | 4 ++++ jar-infer/test-android-lib-jarinfer/build.gradle | 1 - sample-app/build.gradle | 5 ++--- settings.gradle | 14 +++----------- 8 files changed, 22 insertions(+), 20 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 552088dc16..7ce76068c3 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -54,7 +54,7 @@ jobs: - name: Build and test using Gradle and Java 11 uses: eskatos/gradle-command-action@v1 with: - arguments: build -x :sample-app:build + arguments: build if: matrix.java == '11' - name: Build and test using Gradle and Java 17 uses: eskatos/gradle-command-action@v1 diff --git a/build.gradle b/build.gradle index dbc8f5119a..10df553722 100644 --- a/build.gradle +++ b/build.gradle @@ -22,8 +22,16 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:4.1.1' + classpath 'com.android.tools.build:gradle:7.0.4' classpath 'com.vanniktech:gradle-maven-publish-plugin:0.14.2' + // This restriction is needed due to our mix of Android and Java modules; + // without it, the build fails with a weird error. + // See https://stackoverflow.com/questions/70217853/how-to-include-android-project-in-a-gradle-multi-project-build + classpath('org.ow2.asm:asm') { + version { + strictly '9.2' + } + } } } plugins { @@ -31,7 +39,6 @@ plugins { id "net.ltgt.errorprone" version "2.0.1" apply false id "com.github.johnrengelman.shadow" version "6.1.0" apply false id "com.github.kt3k.coveralls" version "2.12.0" apply false - id "com.android.application" version "3.5.0" apply false id "me.champeau.jmh" version "0.6.6" apply false } diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index c882a8456d..adaa99bb1a 100755 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -72,7 +72,6 @@ def build = [ commonscli : "commons-cli:commons-cli:${versions.commonscli}", // android stuff - buildToolsVersion: "30.0.3", compileSdkVersion: 30, ci: "true" == System.getenv("CI"), minSdkVersion: 16, diff --git a/jar-infer/jar-infer-lib/build.gradle b/jar-infer/jar-infer-lib/build.gradle index e150daaa40..638ae2de31 100644 --- a/jar-infer/jar-infer-lib/build.gradle +++ b/jar-infer/jar-infer-lib/build.gradle @@ -39,7 +39,6 @@ dependencies { exclude group: "junit", module: "junit" } testImplementation project(":jar-infer:test-java-lib-jarinfer") - testImplementation project(path: ":jar-infer:test-android-lib-jarinfer", configuration: "default") testImplementation files("${System.properties['java.home']}/../lib/tools.jar") // is there a better way? testRuntimeOnly deps.build.errorProneCheckApi } @@ -65,6 +64,9 @@ test { "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", ] } + if (JavaVersion.current() >= JavaVersion.VERSION_11) { + dependsOn ':jar-infer:test-android-lib-jarinfer:bundleReleaseAar' + } } apply plugin: 'com.vanniktech.maven.publish' diff --git a/jar-infer/jar-infer-lib/src/test/java/com/uber/nullaway/jarinfer/JarInferTest.java b/jar-infer/jar-infer-lib/src/test/java/com/uber/nullaway/jarinfer/JarInferTest.java index 67d53566d8..3a68785a29 100644 --- a/jar-infer/jar-infer-lib/src/test/java/com/uber/nullaway/jarinfer/JarInferTest.java +++ b/jar-infer/jar-infer-lib/src/test/java/com/uber/nullaway/jarinfer/JarInferTest.java @@ -435,6 +435,10 @@ public void toyJARAnnotatingClasses() throws Exception { @Test public void toyAARAnnotatingClasses() throws Exception { + if (System.getProperty("java.version").startsWith("1.8")) { + // We only build the sample Android apps on JDK 11+ + return; + } testAnnotationInAarTemplate( "toyAARAnnotatingClasses", "com.uber.nullaway.jarinfer.toys.unannotated", diff --git a/jar-infer/test-android-lib-jarinfer/build.gradle b/jar-infer/test-android-lib-jarinfer/build.gradle index 6f1cade410..db29e5756a 100644 --- a/jar-infer/test-android-lib-jarinfer/build.gradle +++ b/jar-infer/test-android-lib-jarinfer/build.gradle @@ -20,7 +20,6 @@ sourceCompatibility = 1.8 android { compileSdkVersion deps.build.compileSdkVersion - buildToolsVersion deps.build.buildToolsVersion defaultConfig { minSdkVersion deps.build.minSdkVersion diff --git a/sample-app/build.gradle b/sample-app/build.gradle index 4b4de17cb3..98f0665111 100644 --- a/sample-app/build.gradle +++ b/sample-app/build.gradle @@ -23,7 +23,6 @@ plugins { android { compileSdkVersion deps.build.compileSdkVersion - buildToolsVersion deps.build.buildToolsVersion defaultConfig { applicationId "com.uber.myapplication" @@ -33,8 +32,8 @@ android { versionName "1.0" } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_7 - targetCompatibility JavaVersion.VERSION_1_7 + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 } lintOptions { diff --git a/settings.gradle b/settings.gradle index 2a69fb22e5..6d5619e670 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,19 +4,11 @@ pluginManagement { gradlePluginPortal() google() } - resolutionStrategy { - eachPlugin { - if (requested.id.namespace == "com.android") { - useModule("com.android.tools.build:gradle:${requested.version}") - } - } - } } include ':nullaway' include ':sample-library-model' include ':sample' -include ':sample-app' include ':test-java-lib' include ':test-java-lib-lombok' include ':test-library-models' @@ -29,12 +21,12 @@ include ':jar-infer:jar-infer-lib' include ':jar-infer:jar-infer-cli' include ':jar-infer:test-java-lib-jarinfer' include ':jar-infer:nullaway-integration-test' -include ':jar-infer:test-android-lib-jarinfer' include ':jmh' include ':jdk17-unit-tests' -// On Java 8, the code-coverage-report module fails during Gradle configuration. So, exclude it -// on pre-JDK-11 JVMs +// The following modules require JDK 11 and fail during Gradle configuration on JDK 8 if (JavaVersion.current() >= JavaVersion.VERSION_11) { include ':code-coverage-report' + include ':sample-app' + include ':jar-infer:test-android-lib-jarinfer' }