Skip to content

Choose appropriate minimum JDK for JRuby versions #718

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

Closed
headius opened this issue Mar 10, 2025 · 14 comments · Fixed by #721
Closed

Choose appropriate minimum JDK for JRuby versions #718

headius opened this issue Mar 10, 2025 · 14 comments · Fixed by #721
Assignees

Comments

@headius
Copy link
Contributor

headius commented Mar 10, 2025

JRuby 10 is just about to be released, and master (now hosting 10) will become jruby-head once we unlock jruby-dev-builder (ruby/jruby-dev-builder#9). JRuby 10, unlike 9.4, depends on JDK 21 minimum. Because GHA defaults JAVA_HOME to a Java 17 install, we need to adjust that for all setup-ruby use on JRuby >= 10-snapshot.

Users of JRuby 10 should not have to perform an additional step to choose the proper JDK level, and we can't flip jruby-head builds to 10 until this is fixed.

I am not familiar enough with the codebase or GHA to know where to put this code. The basic requirement is to detect that we're setting up a JRuby version (head or 10+) that requires JDK 21, and alter the JAVA_HOME environment variable to point at the contents of the platform-appropriate JAVA_HOME_21_* variable (see actions/runner-images#9266 for some discussion on that).

@eregon
Copy link
Member

eregon commented Mar 10, 2025

I am not familiar enough with the codebase or GHA to know where to put this code

Please take a look and make a PR yourself, it should be fairly simple.
See

setup-ruby/index.js

Lines 55 to 59 in 277ba2a

if (platform.startsWith('windows-') && engine === 'ruby' && !common.isSelfHostedRunner()) {
installer = require('./windows')
} else {
installer = require('./ruby-builder')
}

so the installer for JRuby is always ruby-builder.js: https://github.com/ruby/setup-ruby/blob/master/ruby-builder.js
It seems best to set JAVA_HOME just after
common.setupPath([path.join(rubyPrefix, 'bin')])

As said in #684 (comment) the logic should be:

IOW I think ideally we would detect if JAVA_HOME is the default, if it is switch to JAVA_HOME_21_X64 instead if available, for all other cases do nothing.

Regardless of the JRuby version if possible, to make it simpler (older JRuby should run fine on JDK 21, maybe even faster).

@headius
Copy link
Contributor Author

headius commented Mar 11, 2025

Regardless of the JRuby version if possible

I am reluctant to switch all existing JRuby 9.4 users to Java 21. It will run fine, and may be faster, but they did not opt into such a change.

However, if it becomes a problem people are concerned about, we can address it then. Hopefully most will not notice.

headius added a commit to headius/setup-ruby that referenced this issue Mar 11, 2025
JRuby 10 requires Java 21. Since the previous default was 17 and
all JRuby releases should work fine on 21, we do this for all
JRuby installs.

Implements ruby#718
headius added a commit to headius/setup-ruby that referenced this issue Mar 11, 2025
JRuby 10 requires Java 21. Since the previous default was 17 and
all JRuby releases should work fine on 21, we do this for all
JRuby installs.

Implements ruby#718
eregon pushed a commit that referenced this issue Mar 12, 2025
* JRuby 10 requires Java 21. Since the previous default was 17 and all JRuby releases should work fine on 21, we do this for all JRuby installs.
* Implements #718
@eregon
Copy link
Member

eregon commented Mar 12, 2025

PR merged, thanks.

@eregon eregon closed this as completed Mar 12, 2025
@eregon eregon linked a pull request Mar 12, 2025 that will close this issue
@NC-piercej
Copy link

We are seeing GitHub Actions failures on ubuntu-latest and jruby-head after this change:

Run ruby/setup-ruby@v1
Modifying PATH
  Entries added to PATH to use selected Ruby:
    /home/runner/.rubies/jruby-head/bin
Downloading Ruby
  https://github.com/ruby/jruby-dev-builder/releases/latest/download/jruby-head-ubuntu-24.04.tar.gz
  Took   1.38 seconds
Extracting  Ruby
  /usr/bin/tar -xz -C /home/runner/.rubies -f /home/runner/work/_temp/ab607910-b37c-4b92-85
  Took   0.42 seconds
Print Ruby version
  /home/runner/.rubies/jruby-head/bin/ruby --version
  Unrecognized VM option 'AutoCreateSharedArchive'
  Error: Could not create the Java Virtual Machine.
  Error: A fatal exception has occurred. Program will exit.
  Took   0.38 seconds
Error: The process '/home/runner/.rubies/jruby-head/bin/ruby' failed with exit code 1

Seems to be related?

@headius
Copy link
Contributor Author

headius commented Mar 13, 2025

Yeah sorry about that... issues that only came up once everything was released. We're working on it in #722.

You may be able to work around it yourself by using setup-java to install Java 21, or reset env JAVA_HOME to JAVA_HOME_21_X64.

@headius
Copy link
Contributor Author

headius commented Mar 13, 2025

work around it yourself

Doing these things before setup-ruby, that is.

@headius
Copy link
Contributor Author

headius commented Mar 13, 2025

You can also switch to JRuby 9.4 builds which is where the 9.4 maintenance line can be tested now. jruby-head is now JRuby 10, requiring Java 21 and supporting up to Ruby 3.4 features.

@eregon
Copy link
Member

eregon commented Mar 13, 2025

@headius
Copy link
Contributor Author

headius commented Mar 13, 2025

@eregon Thank you for merging and releasing.

@NC-piercej Can you confirm your builds are working with jruby-head again?

@ntkme
Copy link
Contributor

ntkme commented Mar 13, 2025

I think it might be better to add a section in README to instruct user to explicitly use https://github.com/actions/setup-java to configure JAVA_HOME if desired, and it needs to be run before setup-ruby. Implicitly changing user's JAVA_HOME might be OK for most of the use case but might also break in unexpected ways.

@NC-piercej
Copy link

I can confirm it is back to working again! 🎉

@headius
Copy link
Contributor Author

headius commented Mar 13, 2025

@ntkme My original suggestion was to call setup-java from setup-ruby. The main concern I have had is that everyone running jruby-head would immediately break because 21 is not the default JDK on GHA yet, and even when 10 is released we don't really want people to have to use setup-java. Basically, setup-ruby should make sure all prerequisites are on the system and working for all Rubies, and for us that means JDK 21 or higher.

The logic I came up with will only change JAVA_HOME if it is too old to run JRuby. If it is already set up (as by setup-java or by user) and works with JRuby, we will not alter JAVA_HOME from the user.

I'm willing to entertain some debate here, though!

@NC-piercej Thank you for confirming, and I guess that also means your library is good to go on JRuby 10!

@ntkme
Copy link
Contributor

ntkme commented Mar 13, 2025

@headius Another idea I have is to have jruby-builder/jruby-dev-builder create an archive that bundles JDK in it and create a ruby launcher wrapper that use the bundled JDK, so there will be no external dependency. In that case, we don't need to modify JAVA_HOME globally.

@headius
Copy link
Contributor Author

headius commented Mar 13, 2025

@ntkme That sounds similar to a question @eregon asked about JRuby having a separate environment variable for Java home. We don't have such a feature currently, but I could see JRUBY_JAVA_HOME being a good option to add to our launchers.

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

Successfully merging a pull request may close this issue.

4 participants