Skip to content

Build on latest Java, test through lowest possible - approach 2#298

Draft
szpak wants to merge 17 commits intomasterfrom
szpak/171-lowestJavaTests
Draft

Build on latest Java, test through lowest possible - approach 2#298
szpak wants to merge 17 commits intomasterfrom
szpak/171-lowestJavaTests

Conversation

@szpak
Copy link
Copy Markdown
Contributor

@szpak szpak commented Jan 16, 2024

This is a reworked variant of #254 (I really liked the approach with overriding javaLauncher for test @TWiStErRob! - originally I wanted to publish binaries locally and pass it to another jobs, which javaLauncher is much easier) with the following changes:

  • e2e tests are executed as before with the latest JDK version (to do not put pressure on Sonatype Nexus)
  • compatibility tests are executed also with JDK 8 (even if built with higher JDK) - sample failure generated on CI on purpose:

Caused by: java.lang.UnsupportedClassVersionError: io/github/gradlenexus/publishplugin/TaskOrchestrationTest has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0


This is not as reliable as separate e2eTests executed with lower JDK, but the binaries are built with higher JDK and running tests leverages that binaries.

Downsides:

  • no way to use test libraries requiring JDK 11+ (e.g. newer Mockito versions)
  • more jobs with compatibility tests on CI
  • slightly more complicated stutter configuration (compatTestJavaauto added)
  • problem with stutter configuration if Gradle drops JDK 8 support (even in toolchain, which is probably not planned yet)
  • ?

Maybe you will have an idea how to improve it further.

./gradlew --version
./gradlew --stacktrace build compatTestJava${{ matrix.jdk }}
./gradlew -q javaToolchains
./gradlew --stacktrace -PnexusPublishPlugin.test.java=${{ matrix.testJdk }} build compatTestJava${{ matrix.jdk }}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid "javaauto" in stutter, we could add testJdk matrix elements manually, adjusting "auto" version to a given JDK version.
Also a shell command could replace "auto" with a proper version.

However, I don't know which of this 3 options is best :-/

@szpak szpak requested a review from TWiStErRob January 16, 2024 22:12
jdk: [11, 17]
name: "OpenJDK ${{ matrix.jdk }}"
jdk: [11, 17, 19]
testJdk: [auto, 8]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we shouldn't have "fail-fast" disabled for that workflow?

Copy link
Copy Markdown
Contributor

@3flex 3flex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Java 21 can be used instead of 19 once #296 is merged.

withType<Test>().matching { it.name.startsWith("compatTest") }.configureEach {
systemProperty("plugin.version", project.version)
}
named<Test>("test").configure {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is equivalent:

Suggested change
named<Test>("test").configure {
test {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that tasks.test {} or project.test {} just to make sure it's at the right level in the build.gradle.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tasks.test

It's sitting in the tasks {} block so can reference test directly here.

// Gradle fully supports running on Java 8: https://docs.gradle.org/current/userguide/compatibility.html,
// so we should allow users to do that too.
jvmTarget = JvmTarget.fromTarget(JavaVersion.VERSION_1_8.toString())
jvmTarget = JvmTarget.fromTarget(project.java.targetCompatibility.toString())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider merging #300 then rebasing.

@TWiStErRob
Copy link
Copy Markdown
Collaborator

I'm yet to do a full review, thanks for looking @3flex !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants