Bug 2020478 - mvn overrides JAVA_HOME so compilation fails
Summary: mvn overrides JAVA_HOME so compilation fails
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: maven
Version: 35
Hardware: All
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Mikolaj Izdebski
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-11-05 02:22 UTC by Michael Katzmann
Modified: 2021-11-14 04:06 UTC (History)
3 users (show)

Fixed In Version: maven-3.6.3-14.fc36 maven-3.6.3-13.fc35
Clone Of:
Environment:
Last Closed: 2021-11-14 04:06:29 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

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.


Note You need to log in before you can comment on or make changes to this bug.