Skip to content

gh-152785: Upgrade Java from 17 to 21 in GHA Android#152783

Open
vstinner wants to merge 2 commits into
python:mainfrom
vstinner:android_upgrade_java
Open

gh-152785: Upgrade Java from 17 to 21 in GHA Android#152783
vstinner wants to merge 2 commits into
python:mainfrom
vstinner:android_upgrade_java

Conversation

@vstinner

@vstinner vstinner commented Jul 1, 2026

Copy link
Copy Markdown
Member

@vstinner vstinner changed the title Upgrade Java from 17 to 21 in GHA Android gh-152785: Upgrade Java from 17 to 21 in GHA Android Jul 1, 2026
@vstinner vstinner marked this pull request as ready for review July 1, 2026 13:10
@vstinner

vstinner commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

@mhsmith: Would you mind reviewing this change?

I tried upgrading Java to Java 25, but Gradle 8 is not compatible with Java 25 and fails with a surprising error:

java.lang.IllegalArgumentException: 25.0.3
	at org.jetbrains.kotlin.com.intellij.util.lang.JavaVersion.parse(JavaVersion.java:307)
	at org.jetbrains.kotlin.com.intellij.util.lang.JavaVersion.current(JavaVersion.java:176)
	at org.jetbrains.kotlin.cli.jvm.modules.JavaVersionUtilsKt.isAtLeastJava9(javaVersionUtils.kt:11)

This change is not needed to upgrade Ubuntu 24.04 to 26.04. It's just that I think that it's a good idea to use newer Java version in our workflow :-)

Android/README.md only mentions a dependency to Java without specifying a version. Should I also update this document to mention that Java 25 and newer is not supported?

Another option would be to upgrade to Gradle and use Java 25. So far, I didn't understand where the Gradle version is specified :-)

@vstinner

vstinner commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

Another option would be to upgrade to Gradle and use Java 25. So far, I didn't understand where the Gradle version is specified :-)

Ah, it seems like the Gradle version comes from the distributionUrl URL of Android/testbed/gradle/wrapper/gradle-wrapper.properties. The latest update was Gradle 8.7 to 8.11.1: commit 2e1544f.

@vstinner

vstinner commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

cc @freakboy3742

persist-credentials: false
- name: Build and test
run: python3 Platforms/Android ci --fast-ci ${{ matrix.arch }}-linux-android
run: JAVA_HOME="${JAVA_HOME_21_X64:-$JAVA_HOME_21_arm64}" python3 Platforms/Android ci --fast-ci ${{ matrix.arch }}-linux-android

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In my tests, Gradle only needs JAVA_HOME.

But would it be more consistent/safer to also set the PATH env var?

Suggested change
run: JAVA_HOME="${JAVA_HOME_21_X64:-$JAVA_HOME_21_arm64}" python3 Platforms/Android ci --fast-ci ${{ matrix.arch }}-linux-android
run: JAVA_HOME="${JAVA_HOME_21_X64:-$JAVA_HOME_21_arm64}" PATH="$JAVA_HOME/bin:$PATH" python3 Platforms/Android ci --fast-ci ${{ matrix.arch }}-linux-android

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.

My understanding is that JAVA_HOME should be all that is needed (or, more strictly: either will work; both is redundant but won't break anything; setting JAVA_HOME is a little cleaner because it only affects the Java configuration).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree with only using JAVA_HOME, but according to the runner documentation, the environment variable ends with _X64 even on the ARM64 runners.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, I see it's different on the macOS runner. In that case, I'm fine with this PR as long as the README is updated as mentioned below.

@freakboy3742 freakboy3742 left a comment

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.

My underlying question about this is the motivation for the change.

I'll defer to @mhsmith on the details here: but I'm not aware of any particular problems with running Gradle with an older (but still LTS-supported) Java; but as you've noted, there are some compatibility issues with using newer Java versions.

Java 21 passes CI, which is the most important criterion here; but it also requires explicitly defining a Java version in the configuration. On the one hand, being explicit about the Java version means we remove an ambiguity about the build environment; but it also means another version that we need to bump/coordinate at some point in the future, rather than accepting the "default java" that the GHA image provides (which skews to the conservative side AFAICT). I'm not sure which is the better option here.

persist-credentials: false
- name: Build and test
run: python3 Platforms/Android ci --fast-ci ${{ matrix.arch }}-linux-android
run: JAVA_HOME="${JAVA_HOME_21_X64:-$JAVA_HOME_21_arm64}" python3 Platforms/Android ci --fast-ci ${{ matrix.arch }}-linux-android

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.

My understanding is that JAVA_HOME should be all that is needed (or, more strictly: either will work; both is redundant but won't break anything; setting JAVA_HOME is a little cleaner because it only affects the Java configuration).

@mhsmith mhsmith left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I prefer to use the following things only in one of the known combinations that have been used by Android Studio:

  • Java version
  • Gradle version (in gradle-wrapper.properties)
  • Android Gradle plugin (AGP) version ("com.android.application" in testbed/build.gradle.kts‎)

I track these combinations in the Chaquopy integration tests. Each subdirectory is named after an AGP version, and it contains a gradle-wrapper.properties with the Gradle version, and a gradle.properties with the Java version.

In this case, the AGP version is 8.10, so we should actually have been on Java 21 already. The gradle.properties mechanism used by the Chaquopy integration tests can't easily be copied to CPython, so I agree setting JAVA_HOME is the way to go.

@mhsmith

mhsmith commented Jul 2, 2026

Copy link
Copy Markdown
Member

Android/README.md only mentions a dependency to Java without specifying a version. Should I also update this document to mention that Java 25 and newer is not supported?

Let's specifically say that versions 17 and 21 are supported. At least one of the buildbots will remain on version 17, so we'll find out if that stops working in the future.

@vstinner

vstinner commented Jul 2, 2026

Copy link
Copy Markdown
Member Author

Let's specifically say that versions 17 and 21 are supported

Ok. I updated the README.md file to add:

Java versions 17 and 21 are supported.

@mhsmith mhsmith added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes skip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants