Bug 2020478

Summary: mvn overrides JAVA_HOME so compilation fails
Product: [Fedora] Fedora Reporter: Michael Katzmann <vk2bea>
Component: mavenAssignee: Mikolaj Izdebski <mizdebsk>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 35CC: java-sig-commits, mizdebsk, msrb
Target Milestone: ---Keywords: Reopened, Triaged
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: maven-3.6.3-14.fc36 maven-3.6.3-13.fc35 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-11-14 04:06:29 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 Michael Katzmann 2021-11-05 02:22:58 UTC
Setting of JAVA_HOME is overwritten by mvn.

/usr/bin/mvn is a script that sources /etc/java/maven.conf which overrides JAVA_HOME. If maven-openjdk11 is installed then this is Java 11, if maven-openjdk17 is installed it is Java 17 regardless of the user's setting of JAVA_HOME.

This means that the compilation of a Java source file with features incompatible with the version set in /etc/java/maven.conf will fail.

e.g:
1. install maven-openjdk11
3. use 'alternatives' to set java to java 17 (JAVA_HOME set to /usr/lib/jvm/java-17-openjdk-17.0.1.0.12-1.rolling.fc35.x86_64)
4. Attempt to use maven to compile Java that has Java 17 features
5. Compilation fails

If MAVEN_SKIP_RC environment variable is set then /etc/mavenrc, /etc/mavenrc and "$HOME/.mavenrc" are ignored. This will mean that JAVA_HOME is not overwritten but maven may then run with a (possible) incompatible version. (setting JAVA_HOME in 
"$HOME/.mavenrc" will also do this)

In /usr/bin/mvn, maven is run with the java specified in JAVACMD.

if [ -z "$JAVA_HOME" ] ; then
  JAVACMD=`which java`
else
  JAVACMD="$JAVA_HOME/bin/java"
fi
It looks to me that a better solution is to set JAVACMD to specific Java version of the installed maven libraries (e.g. 11) and leave alone JAVA_HOME so that the user java files are compiled as expected.

Comment 1 Mikolaj Izdebski 2021-11-05 09:42:29 UTC
Pull request: https://src.fedoraproject.org/rpms/maven/pull-request/31

Comment 2 Fedora Update System 2021-11-05 10:16:24 UTC
FEDORA-2021-8d99f2be15 has been submitted as an update to Fedora 36. https://bodhi.fedoraproject.org/updates/FEDORA-2021-8d99f2be15

Comment 3 Fedora Update System 2021-11-05 10:18:58 UTC
FEDORA-2021-8d99f2be15 has been pushed to the Fedora 36 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 4 Fedora Update System 2021-11-08 10:33:44 UTC
FEDORA-2021-02d9cfd280 has been submitted as an update to Fedora 35. https://bodhi.fedoraproject.org/updates/FEDORA-2021-02d9cfd280

Comment 5 Fedora Update System 2021-11-14 04:06:29 UTC
FEDORA-2021-02d9cfd280 has been pushed to the Fedora 35 stable repository.
If problem still persists, please make note of it in this bug report.