Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to reduce targetCompatibility to Java 11? #66

Closed
mannodermaus opened this issue May 18, 2024 · 1 comment
Closed

Possibility to reduce targetCompatibility to Java 11? #66

mannodermaus opened this issue May 18, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@mannodermaus
Copy link
Contributor

mannodermaus commented May 18, 2024

I'm trying to introduce support for JUnit 5 to Roborazzi, a helpful screenshot testing library that integrates with Robolectric. That library builds its JARs with a target compatibility of Java 11, and this clashes when paired with junit5-robolectric-extension, which outputs Java 17-compatible bytecode. We could keep using Java 17 to build its artifacts, but would you consider dropping its output to Java 11 compatibility? This way, we could extend the potential user base to all projects that still run on Android Gradle Plugin 7.x, for instance. If not, we can probably consider a split target requirement over at the Roborazzi repository (so that only the JUnit 5 stuff requires Java 17 compatibility). Thanks in advance!

@warnyul warnyul added the enhancement New feature or request label May 23, 2024
@warnyul warnyul self-assigned this May 23, 2024
warnyul added a commit that referenced this issue May 23, 2024
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 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
   <component name="KotlinJpsPluginSettings">
-    <option name="version" value="1.9.23" />
+    <option name="version" value="1.9.24" />
   </component>
 </project>
\ 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<Project> {
     }

     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
@warnyul
Copy link
Member

warnyul commented May 23, 2024

A new version available with Java 11 support: https://github.com/apter-tech/junit5-robolectric-extension/releases/tag/0.7.0

@warnyul warnyul closed this as completed May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants