Bug 2096431

Summary: maven:3.6 does not respect JAVA_HOME set by user
Product: Red Hat Enterprise Linux 9 Reporter: jiri vanek <jvanek>
Component: mavenAssignee: Marián Konček <mkoncek>
Status: CLOSED ERRATA QA Contact: Martin Kyral <mkyral>
Severity: high Docs Contact:
Priority: high    
Version: 9.0CC: jdowland, mizdebsk, mkoncek, mkyral, pmikova, sfroberg, zzambers
Target Milestone: rcKeywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: maven-3.6.3-15.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-05-09 07:53:24 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description jiri vanek 2022-06-13 19:28:08 UTC
Description of problem:

JAVA_HOME is not honoured, hard-coded jdk is used instead, thus killing 100% multi-jdk development and purpose of several possible javas in system.

Version-Release number of selected component (if applicable):

maven-3.6.3-14.el9.noarch

Steps to Reproduce:
1. dnf install maven
- that pulls jdk11 in 
2. remove all jdks 
3. extract custom jdk
4 export correctly JAVA_HOME to point to correct custom JDK
5 try to run maven

Actual results:
/usr/bin/mvn --version
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE

or:

Steps to Reproduce:
1. dnf install maven
- that pulls jdk11 in 
3. extract custom jdk
4 export correctly JAVA_HOME to point to correct custom JDK
5 try to run maven

Actual results:
/usr/bin/mvn --version

Will now work, but will use bad JDK - hardcoded instead of appointed one

Expected results:
Maven will use specified JDK without questioning uses actions, as promised in https://fedoraproject.org/wiki/Changes/Decouple_system_java_setting_from_java_command_setting

Additional info:
This popups form time to time in fedora, but usually gets quickly fixed. I'm wondering why and how it bubbled to rhel

Comment 1 Marián Konček 2022-06-16 13:39:45 UTC
Checked on Fedora Rawhide:
# dnf install maven java-latest-openjdk-headless

#  mvn --version
Apache Maven 3.8.5 (Red Hat 3.8.5-2)
Maven home: /usr/share/maven
Java version: 17.0.3, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-17-openjdk-17.0.3.0.7-2.fc37.x86_64
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "5.17.4-200.fc35.x86_64", arch: "amd64", family: "unix"

#  JAVA_HOME=/usr/lib/jvm/java-18-openjdk-18.0.1.0.10-1.rolling.fc37.x86_64/ mvn --version
Apache Maven 3.8.5 (Red Hat 3.8.5-2)
Maven home: /usr/share/maven
Java version: 18.0.1, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-18-openjdk-18.0.1.0.10-1.rolling.fc37.x86_64
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "5.17.4-200.fc35.x86_64", arch: "amd64", family: "unix"

Comment 2 Jonathan Dowland 2022-06-28 14:21:10 UTC
For the OpenJDK containers, we hit this when building OpenJ9 variants. The issue was the value hard-coded into /etc/java/maven.conf. Our solution was to 0 that file in our build process.

Comment 3 jiri vanek 2022-07-25 10:57:24 UTC
(In reply to Marián Konček from comment #1)
> Checked on Fedora Rawhide:
> # dnf install maven java-latest-openjdk-headless
> 
> #  mvn --version
> Apache Maven 3.8.5 (Red Hat 3.8.5-2)
> Maven home: /usr/share/maven
> Java version: 17.0.3, vendor: Red Hat, Inc., runtime:
> /usr/lib/jvm/java-17-openjdk-17.0.3.0.7-2.fc37.x86_64
> Default locale: en, platform encoding: UTF-8
> OS name: "linux", version: "5.17.4-200.fc35.x86_64", arch: "amd64", family:
> "unix"
> 
> #  JAVA_HOME=/usr/lib/jvm/java-18-openjdk-18.0.1.0.10-1.rolling.fc37.x86_64/
> mvn --version
> Apache Maven 3.8.5 (Red Hat 3.8.5-2)
> Maven home: /usr/share/maven
> Java version: 18.0.1, vendor: Red Hat, Inc., runtime:
> /usr/lib/jvm/java-18-openjdk-18.0.1.0.10-1.rolling.fc37.x86_64
> Default locale: en, platform encoding: UTF-8
> OS name: "linux", version: "5.17.4-200.fc35.x86_64", arch: "amd64", family:
> "unix"

I reall Fedora had this glitch in past, how it is possibel that el9 got the broken version.. hard to say.

Comment 4 jiri vanek 2022-07-25 13:11:35 UTC
 curl https://fedoraproject.org/wiki/Changes/Decouple_system_java_setting_from_java_command_setting#Summary | grep JAVA_HOME

   <p>By default, Java applications installed from RPMs are run with JVM found on PATH. We propose to run them with default system JVM, not considering PATH. Users will still be able to override the default using JAVA_HOME environment variable as before.
 <li>if the current environment contains JAVA_HOME variable (typically it doesn't), JVM executable is looked up there</li>
<li>if the configuration specifies JAVA_HOME (by default it doesn't), JVM is looked up there</li>
   <p>If JAVA_HOME is not set (neither in the environment, nor

Comment 5 jiri vanek 2022-07-25 13:21:41 UTC
btw:
 cat    /etc/java/maven.conf 
JAVA_HOME=/usr/lib/jvm/java-11-openjdk

????

cat    /etc/java/java.conf  | grep usr | grep jvm | wc -l
0

??

I guerss something changed since  https://fedoraproject.org/wiki/Changes/Decouple_system_java_setting_from_java_command_setting#Summary

Comment 6 Marián Konček 2022-07-26 09:21:26 UTC
Confirmed on a Beaker machine with RHEL 9:
# dnf install maven java-17-openjdk-headless

# JAVA_HOME=/usr/lib/jvm/jre-17 mvn --version
Apache Maven 3.6.3 (Red Hat 3.6.3-14)
Maven home: /usr/share/maven
Java version: 11.0.16, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-11-openjdk-11.0.16.0.8-2.el9.x86_64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.14.0-130.kpq0.el9.x86_64", arch: "amd64", family: "unix"

Comment 7 Mikolaj Izdebski 2022-08-18 06:35:35 UTC
Confirmed.

Reproducer:
# podman run -it registry.access.redhat.com/ubi9
# dnf -y install maven
# JAVA_HOME=dummy mvn -v

Expected result: exit code 1, message "The JAVA_HOME environment variable is not defined correctly"
Actual result: exit code 0, Maven is ran using JDK 11, it displays version.

Scope of the change: fix maven scripts not to override JAVA_HOME from environment
Gating tests need to be implemented for all JDKs: 8, 11, 17

Comment 8 Mikolaj Izdebski 2022-08-18 06:48:07 UTC
This should already be fixed in Fedora, bug #2020478
Fedora change: https://src.fedoraproject.org/rpms/maven/pull-request/31
This should also be fixed in Maven 3.8 in RHEL 9.2.

Comment 18 Mikolaj Izdebski 2023-02-02 07:53:39 UTC
Note regarding verification and test coverage:
This bug is covered by /Regression/java-home-override test that checks
whether Maven allows overriding JAVA_HOME by calling user.
https://src.fedoraproject.org/tests/maven/blob/main/f/Regression/java-home-override

Comment 19 Mikolaj Izdebski 2023-02-02 15:43:33 UTC
Pre-verified.
Gating tests passed or were waived.
Waivers are justified.

Comment 24 errata-xmlrpc 2023-05-09 07:53:24 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (maven bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2023:2402