From 56f70a99741ca49c72dd05062530e31631f518f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Varga?= Date: Thu, 23 May 2024 13:48:35 +0200 Subject: [PATCH] feat: Build the extension and the plugin with Java 11 (#66) diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml index fe63bb6..148fdd2 100644 --- a/.idea/kotlinc.xml +++ b/.idea/kotlinc.xml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 801d827..272f92d 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -17,7 +17,7 @@ dependencies { java { toolchain { - languageVersion.set(JavaLanguageVersion.of(libs.versions.jvmToolchain.get())) + languageVersion.set(JavaLanguageVersion.of(libs.versions.jvmToolchainMin.get())) } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0769243..aa68d24 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -11,17 +11,19 @@ gradlePluginPublish = "1.2.1" guava = "33.2.0-jre" junit4 = "4.13.2" junit5 = "5.10.2" +jvmToolchainMin = "11" jvmToolchain = "17" kotlin = "1.9.24" kover = "0.8.0" robolectric = "4.12.1" -robolectricAndroidAll = "14-robolectric-10818077" +robolectricAndroidAll = "13-robolectric-9030017" robolectricExtensionGradlePlugin = "0.6.1" # Use when bom also added to the dependencies sources = "sources" [libraries] androidGradle = { module = "com.android.tools.build:gradle", version.ref = "androidGradle" } +androidGradleJdk11 = { module = "com.android.tools.build:gradle", version.require = "7.0.4" } androidxTestExtJunit = { module = "androidx.test.ext:junit", version.ref = "androidxTestExtJunit" } detektFormatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" } detektRulesLibraries = { module = "io.gitlab.arturbosch.detekt:detekt-rules-libraries", version.ref = "detekt" } diff --git a/robolectric-extension-gradle-plugin/build.gradle b/robolectric-extension-gradle-plugin/build.gradle index c69cfc8..4d21850 100644 --- a/robolectric-extension-gradle-plugin/build.gradle +++ b/robolectric-extension-gradle-plugin/build.gradle @@ -17,7 +17,7 @@ buildConfig { } kotlin { - jvmToolchain(libs.versions.jvmToolchain.get().toInteger()) + jvmToolchain(libs.versions.jvmToolchainMin.get().toInteger()) } detekt { @@ -33,12 +33,12 @@ dependencies { detektPlugins(libs.detektFormatting) detektPlugins(libs.detektRulesLibraries) compileOnly(gradleApi()) - compileOnly(libs.androidGradle) + compileOnly(libs.androidGradleJdk11) testImplementation(gradleTestKit()) testImplementation(platform(libs.junit5Bom)) testImplementation(libs.junit5JupiterApi) testImplementation(libs.kotlinTestJUnit5) - testImplementation(libs.androidGradle) + testImplementation(libs.androidGradleJdk11) testRuntimeOnly(libs.junit5JupiterEngine) } diff --git a/robolectric-extension-gradle-plugin/src/main/kotlin/tech/apter/robolectric/junit/jupiter/gradle/plugin/RobolectricJUnitJupiterGradlePlugin.kt b/robolectric-extension-gradle-plugin/src/main/kotlin/tech/apter/robolectric/junit/jupiter/gradle/plugin/RobolectricJUnitJupiterGradlePlugin.kt index 1028f97..1a017e0 100644 --- a/robolectric-extension-gradle-plugin/src/main/kotlin/tech/apter/robolectric/junit/jupiter/gradle/plugin/RobolectricJUnitJupiterGradlePlugin.kt +++ b/robolectric-extension-gradle-plugin/src/main/kotlin/tech/apter/robolectric/junit/jupiter/gradle/plugin/RobolectricJUnitJupiterGradlePlugin.kt @@ -52,7 +52,7 @@ class RobolectricJUnitJupiterGradlePlugin : Plugin { } private fun Project.enableIncludeAndroidResources() { - val androidExtension = extensions.findByName("android") as? CommonExtension<*, *, *, *, *, *> + val androidExtension = extensions.findByName("android") as? CommonExtension<*, *, *, *> @Suppress("UnstableApiUsage") androidExtension?.testOptions?.unitTests?.isIncludeAndroidResources = true } diff --git a/robolectric-extension/build.gradle b/robolectric-extension/build.gradle index 4f48e93..d5baa57 100644 --- a/robolectric-extension/build.gradle +++ b/robolectric-extension/build.gradle @@ -17,7 +17,7 @@ configurations.configureEach { configuration -> } kotlin { - jvmToolchain(libs.versions.jvmToolchain.get().toInteger()) + jvmToolchain(libs.versions.jvmToolchainMin.get().toInteger()) } robolectricJUnitJupiter { diff --git a/robolectric-extension/src/test/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricSandboxBuilderTest.kt b/robolectric-extension/src/test/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricSandboxBuilderTest.kt index bbf131b..4ef46c6 100644 --- a/robolectric-extension/src/test/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricSandboxBuilderTest.kt +++ b/robolectric-extension/src/test/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricSandboxBuilderTest.kt @@ -22,8 +22,8 @@ class JUnit5RobolectricSandboxBuilderTest { fun `Given the same arguments when call build twice then should return two different sandboxes with the same classloader `() { // Given val instrumentationConfiguration = createInstrumentationConfiguration() - val runtimeSdk: Sdk = TestUtil.sdkCollection.getSdk(34) - val compileSdk: Sdk = TestUtil.sdkCollection.getSdk(34) + val runtimeSdk: Sdk = TestUtil.sdkCollection.getSdk(33) + val compileSdk: Sdk = TestUtil.sdkCollection.getSdk(33) val resourcesMode: ResourcesMode = ResourcesMode.BINARY val sqLiteMode: SQLiteMode.Mode = SQLiteMode.Mode.NATIVE @@ -45,11 +45,11 @@ class JUnit5RobolectricSandboxBuilderTest { fun `Given different arguments when call build twice then should return two different sandboxes with different classloaders`() { // Given val instrumentationConfiguration1 = createInstrumentationConfiguration() - val runtimeSdk1: Sdk = TestUtil.sdkCollection.getSdk(34) - val compileSdk1: Sdk = TestUtil.sdkCollection.getSdk(34) + val runtimeSdk1: Sdk = TestUtil.sdkCollection.getSdk(33) + val compileSdk1: Sdk = TestUtil.sdkCollection.getSdk(33) val instrumentationConfiguration2 = createInstrumentationConfiguration() - val runtimeSdk2: Sdk = TestUtil.sdkCollection.getSdk(33) - val compileSdk2: Sdk = TestUtil.sdkCollection.getSdk(33) + val runtimeSdk2: Sdk = TestUtil.sdkCollection.getSdk(32) + val compileSdk2: Sdk = TestUtil.sdkCollection.getSdk(32) val resourcesMode: ResourcesMode = ResourcesMode.BINARY val sqLiteMode: SQLiteMode.Mode = SQLiteMode.Mode.NATIVE diff --git a/robolectric-extension/src/test/resources/robolectric.properties b/robolectric-extension/src/test/resources/robolectric.properties index 979b5ee..3525a65 100644 --- a/robolectric-extension/src/test/resources/robolectric.properties +++ b/robolectric-extension/src/test/resources/robolectric.properties @@ -1 +1,2 @@ -sdk=34 +sdk=33 +packageName=tech.apter.junit.jupiter.robolectric --- .idea/kotlinc.xml | 2 +- buildSrc/build.gradle | 2 +- gradle/libs.versions.toml | 4 +++- robolectric-extension-gradle-plugin/build.gradle | 6 +++--- .../plugin/RobolectricJUnitJupiterGradlePlugin.kt | 2 +- robolectric-extension/build.gradle | 2 +- .../internal/JUnit5RobolectricSandboxBuilderTest.kt | 12 ++++++------ .../src/test/resources/robolectric.properties | 3 ++- 8 files changed, 18 insertions(+), 15 deletions(-) diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml index fe63bb6..148fdd2 100644 --- a/.idea/kotlinc.xml +++ b/.idea/kotlinc.xml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 801d827..272f92d 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -17,7 +17,7 @@ dependencies { java { toolchain { - languageVersion.set(JavaLanguageVersion.of(libs.versions.jvmToolchain.get())) + languageVersion.set(JavaLanguageVersion.of(libs.versions.jvmToolchainMin.get())) } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0769243..aa68d24 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -11,17 +11,19 @@ gradlePluginPublish = "1.2.1" guava = "33.2.0-jre" junit4 = "4.13.2" junit5 = "5.10.2" +jvmToolchainMin = "11" jvmToolchain = "17" kotlin = "1.9.24" kover = "0.8.0" robolectric = "4.12.1" -robolectricAndroidAll = "14-robolectric-10818077" +robolectricAndroidAll = "13-robolectric-9030017" robolectricExtensionGradlePlugin = "0.6.1" # Use when bom also added to the dependencies sources = "sources" [libraries] androidGradle = { module = "com.android.tools.build:gradle", version.ref = "androidGradle" } +androidGradleJdk11 = { module = "com.android.tools.build:gradle", version.require = "7.0.4" } androidxTestExtJunit = { module = "androidx.test.ext:junit", version.ref = "androidxTestExtJunit" } detektFormatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" } detektRulesLibraries = { module = "io.gitlab.arturbosch.detekt:detekt-rules-libraries", version.ref = "detekt" } diff --git a/robolectric-extension-gradle-plugin/build.gradle b/robolectric-extension-gradle-plugin/build.gradle index c69cfc8..4d21850 100644 --- a/robolectric-extension-gradle-plugin/build.gradle +++ b/robolectric-extension-gradle-plugin/build.gradle @@ -17,7 +17,7 @@ buildConfig { } kotlin { - jvmToolchain(libs.versions.jvmToolchain.get().toInteger()) + jvmToolchain(libs.versions.jvmToolchainMin.get().toInteger()) } detekt { @@ -33,12 +33,12 @@ dependencies { detektPlugins(libs.detektFormatting) detektPlugins(libs.detektRulesLibraries) compileOnly(gradleApi()) - compileOnly(libs.androidGradle) + compileOnly(libs.androidGradleJdk11) testImplementation(gradleTestKit()) testImplementation(platform(libs.junit5Bom)) testImplementation(libs.junit5JupiterApi) testImplementation(libs.kotlinTestJUnit5) - testImplementation(libs.androidGradle) + testImplementation(libs.androidGradleJdk11) testRuntimeOnly(libs.junit5JupiterEngine) } diff --git a/robolectric-extension-gradle-plugin/src/main/kotlin/tech/apter/robolectric/junit/jupiter/gradle/plugin/RobolectricJUnitJupiterGradlePlugin.kt b/robolectric-extension-gradle-plugin/src/main/kotlin/tech/apter/robolectric/junit/jupiter/gradle/plugin/RobolectricJUnitJupiterGradlePlugin.kt index 1028f97..1a017e0 100644 --- a/robolectric-extension-gradle-plugin/src/main/kotlin/tech/apter/robolectric/junit/jupiter/gradle/plugin/RobolectricJUnitJupiterGradlePlugin.kt +++ b/robolectric-extension-gradle-plugin/src/main/kotlin/tech/apter/robolectric/junit/jupiter/gradle/plugin/RobolectricJUnitJupiterGradlePlugin.kt @@ -52,7 +52,7 @@ class RobolectricJUnitJupiterGradlePlugin : Plugin { } private fun Project.enableIncludeAndroidResources() { - val androidExtension = extensions.findByName("android") as? CommonExtension<*, *, *, *, *, *> + val androidExtension = extensions.findByName("android") as? CommonExtension<*, *, *, *> @Suppress("UnstableApiUsage") androidExtension?.testOptions?.unitTests?.isIncludeAndroidResources = true } diff --git a/robolectric-extension/build.gradle b/robolectric-extension/build.gradle index 4f48e93..d5baa57 100644 --- a/robolectric-extension/build.gradle +++ b/robolectric-extension/build.gradle @@ -17,7 +17,7 @@ configurations.configureEach { configuration -> } kotlin { - jvmToolchain(libs.versions.jvmToolchain.get().toInteger()) + jvmToolchain(libs.versions.jvmToolchainMin.get().toInteger()) } robolectricJUnitJupiter { diff --git a/robolectric-extension/src/test/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricSandboxBuilderTest.kt b/robolectric-extension/src/test/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricSandboxBuilderTest.kt index bbf131b..4ef46c6 100644 --- a/robolectric-extension/src/test/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricSandboxBuilderTest.kt +++ b/robolectric-extension/src/test/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricSandboxBuilderTest.kt @@ -22,8 +22,8 @@ class JUnit5RobolectricSandboxBuilderTest { fun `Given the same arguments when call build twice then should return two different sandboxes with the same classloader `() { // Given val instrumentationConfiguration = createInstrumentationConfiguration() - val runtimeSdk: Sdk = TestUtil.sdkCollection.getSdk(34) - val compileSdk: Sdk = TestUtil.sdkCollection.getSdk(34) + val runtimeSdk: Sdk = TestUtil.sdkCollection.getSdk(33) + val compileSdk: Sdk = TestUtil.sdkCollection.getSdk(33) val resourcesMode: ResourcesMode = ResourcesMode.BINARY val sqLiteMode: SQLiteMode.Mode = SQLiteMode.Mode.NATIVE @@ -45,11 +45,11 @@ class JUnit5RobolectricSandboxBuilderTest { fun `Given different arguments when call build twice then should return two different sandboxes with different classloaders`() { // Given val instrumentationConfiguration1 = createInstrumentationConfiguration() - val runtimeSdk1: Sdk = TestUtil.sdkCollection.getSdk(34) - val compileSdk1: Sdk = TestUtil.sdkCollection.getSdk(34) + val runtimeSdk1: Sdk = TestUtil.sdkCollection.getSdk(33) + val compileSdk1: Sdk = TestUtil.sdkCollection.getSdk(33) val instrumentationConfiguration2 = createInstrumentationConfiguration() - val runtimeSdk2: Sdk = TestUtil.sdkCollection.getSdk(33) - val compileSdk2: Sdk = TestUtil.sdkCollection.getSdk(33) + val runtimeSdk2: Sdk = TestUtil.sdkCollection.getSdk(32) + val compileSdk2: Sdk = TestUtil.sdkCollection.getSdk(32) val resourcesMode: ResourcesMode = ResourcesMode.BINARY val sqLiteMode: SQLiteMode.Mode = SQLiteMode.Mode.NATIVE diff --git a/robolectric-extension/src/test/resources/robolectric.properties b/robolectric-extension/src/test/resources/robolectric.properties index 979b5ee..3525a65 100644 --- a/robolectric-extension/src/test/resources/robolectric.properties +++ b/robolectric-extension/src/test/resources/robolectric.properties @@ -1 +1,2 @@ -sdk=34 +sdk=33 +packageName=tech.apter.junit.jupiter.robolectric