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

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

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

szpak
Copy link
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.

@@ -38,4 +39,5 @@ jobs:
- name: Test cross Java versions compatibility
run: |
./gradlew --version
./gradlew --stacktrace build compatTestJava${{ matrix.jdk }}
./gradlew -q javaToolchains
./gradlew --stacktrace -PnexusPublishPlugin.test.java=${{ matrix.testJdk }} build compatTestJava${{ matrix.jdk }}
Copy link
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
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
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.

@@ -261,6 +288,19 @@ tasks {
withType<Test>().matching { it.name.startsWith("compatTest") }.configureEach {
systemProperty("plugin.version", project.version)
}
named<Test>("test").configure {
Copy link
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
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.

@@ -174,7 +190,7 @@ kotlin.target.compilations.configureEach {
compilerOptions.configure {
// 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
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
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