brew update and can still reproduce the problem?brew doctor, fixed all issues and can still reproduce the problem?brew gist-logs <formula> (where <formula> is the name of the formula that failed) and included the output link?brew gist-logs didn't work: ran brew config and brew doctor and included their output with your issue?I apologize in advance if this is not the appropriate repo for this issue! I'm happy to open this elsewhere, I just wasn't sure where the appropriate place was. The main brew repo didn't seem like right place, and the code change that's affecting me was in this repo.
I'd like mvn to launch with the version of java specified via JAVA_VERSION when JAVA_HOME is unset. This makes it much easier to change the java version, instead of typing out the whole path to JDK.
I was able to do this until the latest brew upgrade. #49845 seems like the change that modified the old behavior.
With the latest brew upgrade of maven, the /usr/local/bin/mvn script sets JAVA_HOME to /usr/local/opt/openjdk if JAVA_HOME is unset. This leads to maven always launching with java 13 (or whatever happens to be the latest openjdk from the openjdk formula) instead of the JAVA_VERSION I've configured.
Command output
$ echo $JAVA_VERSION
1.8
$ mvn --version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/Cellar/maven/3.6.3_1/libexec
Java version: 13.0.2, vendor: N/A, runtime: /usr/local/Cellar/openjdk/13.0.2+8_2/libexec/openjdk.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.6", arch: "x86_64", family: "mac"
mvn should launch with java 8 when JAVA_VERSION is set to 1.8
brew install commands)brew install maven
unset JAVA_HOME
export JAVA_VERSION=1.8
mvn --version
I can't really find documentation on how this is supposed to work or what application is responsible for honoring this. Could you link some documentation on JAVA_VERSION?
Interesting, I can't seem to find documentation about it either on google... But it's a part of the /usr/libexec/java_home tool: https://developer.apple.com/library/archive/qa/qa1170/_index.html
The default /usr/bin/java on macos isn't a "real" JDK or JDE - it uses that java_home tool to dynamically pick a java installation to use and delegates to it.
I guess this may not be a widely used feature since it doesn't appear to be documented. But I know the java_home tool definitely honors the JAVA_VERSION variable:
$ unset JAVA_VERSION
$ unset JAVA_HOME
$ /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home
$ /usr/bin/java -version
openjdk version "13.0.2" 2020-01-14
OpenJDK Runtime Environment AdoptOpenJDK (build 13.0.2+8)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 13.0.2+8, mixed mode, sharing)
$
$ export JAVA_VERSION=11
$ /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
$ /usr/bin/java -version
openjdk version "11.0.6" 2020-01-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.6+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.6+10, mixed mode)
I'm not sure about JAVA_VERSION but I'm facing the same fundamental problem: I am no longer able to use Maven with a version 8 JDK. It appears that the formula recently changed from having a general Java dependency to directly depending on openjdk, which may be the underlying root cause (?)
For software related to Java development, you can still choose your preferred version by setting JAVA_HOME.
You could do something like this:
JAVA_HOME="$(/usr/libexec/java_home -v "$JAVA_VERSION")"
Right, but then I have to run 2 commands each time I want to switch java versions instead of just a single export JAVA_VERSION=<version>. I can definitely add an alias/function as a wrapper around mvn to do that for me, but it seems odd to change how mvn was previously picking up its java executable.
While it's unfortunate that your workflow is broken, I can't find anything on JAVA_VERSION still. If you can help us out by pointing to where you found this variable and how it should work maybe we can restore the previous behaviour.
Unfortunately, I don't remember where I found the variable, it's been several years. I was unable to find it again in a google search a couple of days ago. But I did learn about /usr/libexec/java_home from the documentation linked above and figured out that that's what is using my JAVA_VERSION even though it's not explicitly documented. Those docs also say that /usr/libexec/java_home is the apple-recommended way to locate a java installation. So I guess thinking about it more, JAVA_VERSION specifically isn't really the problem - the fact that the new mvn command doesn't honor the java that's selected by /usr/libexec/java_home is the real issue. There could be other env vars that /usr/libexec/java_home uses that I don't know about that could break someone's workflow.
Why the dependency change? If I upgrade Maven with home-brew, I'm going to have to start ignoring the dependency? I already have adopt-openjdk-8 installed, I don't particularly want to install openjdk13 for Maven when Maven works fine with the JDK I'm using for other things ...
Because homebrew works better when it controls all parts of the build stack. The only reason we allowed other things is that Java is a pain to build and nobody bothered to add it to homebrew yet.
@SMillerDev That's clearly true for most packages, but I would prefer not having a specific dependency forced on a development tool like gradle or maven: most of us have workflows and/or other dependencies because of guidelines, company policies, project requirements, etc.
I, like @geoffreywiseman, use adoptopenjdk8 (because I have to due to project requirements, in this instance), and while installing openjdk on the side certainly won't kill me, I don't really see the point of that.
(At least, give me an --ignore-dependencies flag in brew upgrade as well 😝)
most of us have workflows and/or other dependencies because of guidelines, company policies, project requirements, etc.
Those are none of my concerns, my only concern is to make homebrew run easier for the majority of people. Installing something that isn't macOS specific and is tested for compatibility on every update makes that happen.
I, like @geoffreywiseman, use adoptopenjdk8
JAVA_HOME to the resque
(At least, give me an --ignore-dependencies flag in brew upgrade as well 😝)
I'm eagerly awaiting your pull request.
Since nobody is able to provide documentation that says JAVA_VERSION should work to begin with I'm closing this issue. It's only attracting people disagreeing with the switch and nothing productive.
? I did provide documentation about /usr/libexec/java_home and showed that it's where JAVA_VERSION is getting picked up.
I really can't find anything about JAVA_VERSION.
I ran echo $JAVA_VERSION in multiple linux docker containers, and it was never set to anything. Maybe it was a mac only thing back then in the time of java 8?
Right, but then I have to run 2 commands each time I want to switch java version
So at the end this is the only remaining issue? You could just alias both commands in your shell profile to a single one.
I have the feeling that /usr/libexec/java_home is a mac only command, for mac only system java versions. https://medium.com/notes-for-geeks/java-home-and-java-home-on-macos-f246cab643bd says:
java_home is the best way on macOS to execute a Java command ...jdk/Contents/Home/bin/
for a specific version of the JDK. And it is independent of the setting of JAVA_HOME.
So both concepts are independent, and if you want to set a specific JAVA, our recommendation is to use JAVA_HOME.
As a side note for anyone else wrestling with this — another option I am considering is to use SDKMAN (https://sdkman.io/) for Java-based dependencies; that hasn’t been appealing to me before (fewer package managers feels better) but maybe an alternate solution for people with more complex JVM needs than makes sense for Homebrew to support? I haven’t tried it so I am not recommending it but thought worth suggesting as an option.
I really can't find anything about JAVA_VERSION.
It's used by Apple's JavaLaunching.framework. It's basically something specific to Apple's Java wrappers (/usr/bin/java, /usr/libexec/java_home, etc.). Since Homebrew mvn doesn't invoke that anymore, and instead invokes Homebrew OpenJDK's java directly, JAVA_VERSION no longer has any effect.
Unfortunately, if it were to use /usr/bin/java then Homebrew's OpenJDK wouldn't be invoked by default which would mean it's broken out-of-the-box for some users. sudo ln -sfn $(brew --prefix)/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk must be run for /usr/bin/java to find Homebrew's OpenJDK.
sudo ln -sfn $(brew --prefix)/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdkmust be run for/usr/bin/javato find Homebrew's OpenJDK.
That's why it's part of the caveats: https://github.com/Homebrew/homebrew-core/blob/master/Formula/openjdk.rb#L56-L59
Yes, my point was since we don't do it automatically then we shouldn't change maven to use /usr/bin/java and thus this issue is a "won't fix"/"working as intended". If you disagree, we can perhaps change maven so that it does.
Otherwise, if we really wanted to bring back JAVA_VERSION flexibility, we'd have to have our own env wrapper script.
FWIW my maven still uses the correct version of java after the upgrade. I have this in my .bash_profile:
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
and that resolves to /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home
Most helpful comment
Why the dependency change? If I upgrade Maven with home-brew, I'm going to have to start ignoring the dependency? I already have adopt-openjdk-8 installed, I don't particularly want to install openjdk13 for Maven when Maven works fine with the JDK I'm using for other things ...