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

After setup of Java 17, subprocess still runs with 11 #701

Open
2 of 5 tasks
headius opened this issue Oct 22, 2024 · 5 comments
Open
2 of 5 tasks

After setup of Java 17, subprocess still runs with 11 #701

headius opened this issue Oct 22, 2024 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@headius
Copy link

headius commented Oct 22, 2024

Description:

The JRuby build installs specific versions of JDK to build and run tests with, but it seems like any JRuby subcommand run by the build is picking up a Java 11 install regardless of the setup-java JDK version.

This recently came up here: https://github.com/jruby/jruby/pull/8378/checks#step:2:4079

The JRuby build apparently ran with Java 17 (creating org/jruby/Main with bytecode version 61), but when a later part of the build shells out to run JRuby it appears to run with Java 11 (failing to load JRuby because it supports up to bytecode version 55).

I do not see how it could be picking up Java 11 in the subprocess.

Task version:

"v4"

Platform:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

Repro steps:

See failed build here: https://github.com/jruby/jruby/pull/8378/checks#step:2:4079

Expected behavior:

All Java-related commands should run with the setup-java JDK version (17 in this case).

Actual behavior:

It seems that some commands (subprocess run from maven, for example) is picking up Java 11 somewhere.

@headius headius added bug Something isn't working needs triage labels Oct 22, 2024
@priyagupta108
Copy link
Contributor

Hi @headius 👋,
Thank you for your report. We will investigate the issue and get back to you as soon as we have updates.

@headius
Copy link
Author

headius commented Oct 30, 2024

I believe I have worked around it temporarily by explicitly removing the preinstalled JDK packages, installing the version I need, and proceeding from there. I have no theories as to why it picks up one of the preinstalled JDKs in a subprocess of Maven.

headius added a commit to headius/jruby that referenced this issue Oct 30, 2024
This installs openjdk-17-jdk as the only system JDK so that if
maven subcommands fall back on the system they can still run JRuby
build for 17+. It should only get used in that case.

See actions/setup-java#701
headius added a commit to headius/jruby that referenced this issue Oct 30, 2024
This installs openjdk-17-jdk as the only system JDK so that if
maven subcommands fall back on the system they can still run JRuby
build for 17+. It should only get used in that case.

See actions/setup-java#701
@priyagupta108
Copy link
Contributor

Hi @headius,
It looks like the Action worked correctly. The logs indicate that the JAVA_HOME is correctly set to Java 17, and I observe the same error occurring when running with Java 21.
I attempted to reproduce the issue on a simple project, and everything functioned as expected. Therefore, I believe this might be an issue specific to your setup.
Could you please try to reproduce the issue outside of your repository on a different simple project?

@headius
Copy link
Author

headius commented Nov 5, 2024

@priyagupta108 A simpler project probably would not show the same effect, but it might be possible to simulate enough of it by having Maven shell out to a subprocess and see if it picks the wrong JDK.

Notice that in my subsequent commits I had to remove all the "wrong" JDKs that were installed by default or they would be selected; it is almost as if something in either Maven or the toolchain around it is defaulting to /usr/bin/java which probably was still set up as the java alternative for Ubuntu. This might happen if, for example, the subprocess env loses the custom PATH set up by setup-java (I assume it sets PATH to the requested JDK?).

Given the default set of JDKs, perhaps there's more that setup-ruby could do to make the JDK it installs actually be registered as the default JDK for the system?

@priyagupta108
Copy link
Contributor

@headius 👋 , Thank you for the detailed explanation.
I attempted to reproduce the issue by setting up a similar environment, but I was unable to replicate the problem.
The setup-java action sets the PATH to the requested JDK version but does not switch versions through update-alternatives. If the specified Java version is available in the hosted toolcache directory, the action will add Java's bin directory to the PATH and create the JAVA_HOME environment variable. If the specified version is not available, the action will download it to the hosted toolcache directory, add it to the PATH, and create the JAVA_HOME environment variable. In most cases, setting the JAVA_HOME environment variable is sufficient to specify which Java version should be used by tools and scripts.
However, some tools and subprocesses might not respect the JAVA_HOME environment variable and instead rely on the system's default java and javac.
As a workaround, you can update the system's default Java version using the update-alternatives command. This ensures that the correct Java version is used even if JAVA_HOME is not respected. Here is a sample configuration:

- name: Set alternatives for java and javac
  run: |
    sudo update-alternatives --set java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java
    sudo update-alternatives --set javac /usr/lib/jvm/temurin-17-jdk-amd64/bin/javac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants