Skip to content

Commit

Permalink
MBS-9506 Fix incremental room build check for Java 11 (#576)
Browse files Browse the repository at this point in the history
MBS-9506 Fix incremental room build check for Java 11

disable failing tests

RoomProcessor uses SimpleJavaVersion that uses java.runtime.version system property to validate for incrementality

We don't know a way to mutate system properties per test in gradleTestKit

https://android.googlesource.com/platform/frameworks/support/+/refs/heads/androidx-master-dev/room/compiler/src/main/kotlin/androidx/room/RoomProcessor.kt
  • Loading branch information
eugene-krivobokov authored Sep 28, 2020
1 parent 53f45e6 commit e822218
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions subprojects/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ android.useAndroidX=true
# The next version of all artifacts
# Scheme: year.<version>
projectVersion=2020.21
# TODO: MBS-9285 - https://github.com/gradle/gradle/issues/12660
systemProp.kotlinVersion=1.3.72
systemProp.androidGradlePluginVersion=4.0.1
# Disable console output https://github.com/autonomousapps/dependency-analysis-android-gradle-plugin/issues/202
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,23 @@ internal abstract class IncrementalKaptTask : CheckTaskWithMode() {
}

private fun checkAnnotationProcessors() {
project.subprojects.forEach { subproject ->
if (subproject.hasKotlinKapt && subproject.hasRoomKapt) {
mode.get().check(subproject) {
if (RoomIncrementalKaptChecker(subproject).isSupported()) {
CheckResult.Ok
} else {
CheckResult.Failed(collectErrorMessage())
}
val subProject = project.subprojects.firstOrNull {
it.hasKotlinKapt && it.hasRoomKapt
}
if (subProject != null) {
mode.get().check(subProject) {
if (RoomIncrementalKaptChecker(subProject).isSupported()) {
CheckResult.Ok
} else {
CheckResult.Failed(collectErrorMessage())
}
}
}
}

private fun collectErrorMessage() = """
Incremental KAPT is turned on (kapt.incremental.apt=true) but Room does not support it in current conditions.
You have to use JDK embedded in Android Studio 3.5.0-beta02 and higher.
You have to use JDK 11 and higher or embedded one in Android Studio 3.5.0-beta02 and higher.
Current JDK is ${System.getProperty("java.runtime.version")} provided by ${System.getProperty("java.vendor")}.
https://avito-tech.github.io/avito-android/docs/projects/buildchecks/#room
""".trimIndent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.avito.android.plugin.build_param_check.incremental_check

import com.avito.kotlin.dsl.withType
import com.avito.utils.logging.ciLogger
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.internal.KaptGenerateStubsTask
import java.net.URLClassLoader
Expand All @@ -12,6 +13,9 @@ internal class RoomIncrementalKaptChecker(
) {

fun isSupported(): Boolean {
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_11)) {
return true
}
val processor = createRoomProcessor()
val suppressedExceptions = mutableListOf<Exception>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.avito.test.gradle.AndroidAppModule
import com.avito.test.gradle.TestProjectGenerator
import com.avito.test.gradle.gradlew
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test

import org.junit.jupiter.api.io.TempDir
Expand All @@ -30,6 +31,7 @@ internal class IncrementalKaptTaskTest {
)
}

@Disabled("Can't change java version in tests, see commit message [MBS-9506]")
@Test
fun `build success with warning - unsupported Java version`() {
generateProject(mode = "warning")
Expand All @@ -42,6 +44,7 @@ internal class IncrementalKaptTaskTest {
)
}

@Disabled("Can't change java version in tests, see commit message [MBS-9506]")
@Test
fun `build fail - unsupported Java version`() {
generateProject(mode = "fail")
Expand Down Expand Up @@ -97,6 +100,7 @@ internal class IncrementalKaptTaskTest {
":checkIncrementalKapt",
"-ParchPersistenceVersion=2.2.4",
"-Pkapt.incremental.apt=true",
"-Djava.version=$javaVersion",
"-Djava.runtime.version=$javaVersion",
"-Djava.vendor=Avito",
expectFailure = expectFailure
Expand Down

0 comments on commit e822218

Please sign in to comment.