Share Robolectric JVM setup in a convention plugin#9598
Closed
yschimke wants to merge 1 commit into
Closed
Conversation
Both okhttp and android-test configure their test JVMs for Robolectric, in different ways: android-test opened nine JDK packages via the Android Gradle Plugin's unitTests DSL, while okhttp stripped the --add-opens flags the plugin adds when running on Java 8. Move both into okhttp.robolectric-conventions so there is one place describing what Robolectric needs from the JVM. Also skip tests that can only run on an Android SDK the test JVM can't sandbox. Robolectric needs Java 21 to build an SDK 37 sandbox, and fails the test class outright on Java 17. Setting robolectric.enabledSdks below Java 21 leaves those tests unselected instead, which scales as more of them arrive without naming each one in the build.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
okhttpandandroid-testboth configure their test JVMs for Robolectric, in different ways:android-testopened nine JDK packages through AGP'sunitTestsDSL.okhttpstripped the--add-opensflags AGP adds, for the Java 8 build.This moves both into a new
okhttp.robolectric-conventionsplugin, so there's one place describing what Robolectric needs from the JVM.It also adds a guard for Android SDKs the test JVM can't sandbox. Robolectric needs Java 21 to create an SDK 37 sandbox and fails the test class outright on Java 17:
Setting
robolectric.enabledSdksbelow Java 21 leaves those tests unselected instead.DefaultSdkPicker.selectSdksintersects a test's configured SDKs with that set, and an empty intersection yields no children rather than an error. Preferred over excluding test classes by name in the build, since it needs no bookkeeping as more SDK 37 tests arrive.No test currently requests SDK 37, so this is a no-op on master today — it's groundwork for #9596, which adds the first one.
Test plan
:okhttp:testAndroidHostTestand:android-test:teston Java 21 and with-Ptest.java.version=17; 81 host tests either way, unchanged from master.spotlessCheck.