diff --git a/src/main/groovy/org/gradle/android/workarounds/JdkImageWorkaround.groovy b/src/main/groovy/org/gradle/android/workarounds/JdkImageWorkaround.groovy index 4470956a..65c68291 100644 --- a/src/main/groovy/org/gradle/android/workarounds/JdkImageWorkaround.groovy +++ b/src/main/groovy/org/gradle/android/workarounds/JdkImageWorkaround.groovy @@ -3,6 +3,7 @@ package org.gradle.android.workarounds import com.google.common.annotations.VisibleForTesting import com.google.common.collect.Lists import org.gradle.android.AndroidIssue +import org.gradle.android.Versions import org.gradle.api.Project import org.gradle.api.artifacts.transform.CacheableTransform import org.gradle.api.artifacts.transform.InputArtifact @@ -188,14 +189,16 @@ class JdkImageWorkaround implements Workaround { ) } - // Capture the module descriptor ignoring the version, which is not enforced anyways - File moduleInfoFile = new File(targetDir, 'java.base/module-info.class') - ModuleDescriptor descriptor = captureModuleDescriptorWithoutVersion(moduleInfoFile) - File descriptorData = new File(targetDir, "module-descriptor.txt") - descriptorData.text = serializeDescriptor(descriptor) - - fileOperations.delete { - delete(moduleInfoFile) + // Starting with AGP 8 only the major Java version is stored in the output so we don't need any normalization + if (Versions.CURRENT_ANDROID_VERSION.major < 8) { + // Capture the module descriptor ignoring the version, which is not enforced anyways + File moduleInfoFile = new File(targetDir, 'java.base/module-info.class') + ModuleDescriptor descriptor = captureModuleDescriptorWithoutVersion(moduleInfoFile) + File descriptorData = new File(targetDir, "module-descriptor.txt") + descriptorData.text = serializeDescriptor(descriptor) + fileOperations.delete { + delete(moduleInfoFile) + } } } diff --git a/src/test/groovy/org/gradle/android/JdkImageWorkaroundTest.groovy b/src/test/groovy/org/gradle/android/JdkImageWorkaroundTest.groovy index af866c58..27a40a39 100644 --- a/src/test/groovy/org/gradle/android/JdkImageWorkaroundTest.groovy +++ b/src/test/groovy/org/gradle/android/JdkImageWorkaroundTest.groovy @@ -257,4 +257,57 @@ class JdkImageWorkaroundTest extends AbstractTest { buildResult.task(':library:compileDebugJavaWithJavac').outcome == TaskOutcome.FROM_CACHE buildResult.task(':library:compileReleaseJavaWithJavac').outcome == TaskOutcome.FROM_CACHE } + + def "jdkImage is normalized when using different toolchain configuration"() { + + Assume.assumeTrue("Android Gradle Plugin < 8", androidVersion >= VersionNumber.parse("8.0")) + + + def gradleVersion = TestVersions.latestSupportedGradleVersionFor(androidVersion) + SimpleAndroidApp.builder(temporaryFolder.root, cacheDir) + .withAndroidVersion(androidVersion) + .withKotlinDisabled() + .withToolchainVersion("19") + .withSourceCompatibility(JavaVersion.VERSION_1_9) + .withDatabindingDisabled() + .build() + .writeProject() + + when: + BuildResult buildResult = withGradleVersion(gradleVersion.version) + .withProjectDir(temporaryFolder.root) + .withArguments( + "clean", "testDebug", "testRelease", "assemble", + "--build-cache" + ).build() + + then: + buildResult.task(':app:compileDebugJavaWithJavac').outcome == TaskOutcome.SUCCESS + buildResult.task(':library:compileDebugJavaWithJavac').outcome == TaskOutcome.SUCCESS + + buildResult.task(':app:compileDebugUnitTestJavaWithJavac').outcome == TaskOutcome.SUCCESS + buildResult.task(':library:compileDebugUnitTestJavaWithJavac').outcome == TaskOutcome.SUCCESS + + when: + buildResult = withGradleVersion(gradleVersion.version) + .withProjectDir(temporaryFolder.root) + .withArguments( + "clean", "testDebug", "testRelease", "assemble", + "--build-cache" + ).build() + + then: + buildResult.task(':app:compileDebugJavaWithJavac').outcome == TaskOutcome.FROM_CACHE + buildResult.task(':app:compileReleaseJavaWithJavac').outcome == TaskOutcome.FROM_CACHE + buildResult.task(':library:compileDebugJavaWithJavac').outcome == TaskOutcome.FROM_CACHE + buildResult.task(':library:compileReleaseJavaWithJavac').outcome == TaskOutcome.FROM_CACHE + + buildResult.task(':app:compileDebugUnitTestJavaWithJavac').outcome == TaskOutcome.FROM_CACHE + buildResult.task(':app:compileReleaseUnitTestJavaWithJavac').outcome == TaskOutcome.FROM_CACHE + buildResult.task(':library:compileDebugUnitTestJavaWithJavac').outcome == TaskOutcome.FROM_CACHE + buildResult.task(':library:compileReleaseUnitTestJavaWithJavac').outcome == TaskOutcome.FROM_CACHE + + where: + androidVersion << TestVersions.latestAndroidVersions + } }