scalacenter / bloop

Bloop is a build server and CLI tool to compile, test and run Scala fast from any editor or build tool.
https://scalacenter.github.io/bloop/
Apache License 2.0
901 stars 202 forks source link

Unexpected JDK detection error in macOS #1150

Closed guizmaii closed 1 month ago

guizmaii commented 4 years ago

"To use Java command-line tools you need to install a JDK"

Here's what I do:

➜  ~ bloop server
Defaulting on nailgun port 8212
There is no server running at port 8212
Starting the bloop server... this may take a few seconds
Running /usr/local/Cellar/bloop/1.4.0-RC1/bin/blp-server as a jar...
Shelling out with '['java', '-jar', '/usr/local/Cellar/bloop/1.4.0-RC1/bin/blp-server']' ...
Error: Invalid or corrupt jarfile /usr/local/Cellar/bloop/1.4.0-RC1/bin/blp-server
Running /usr/local/Cellar/bloop/1.4.0-RC1/bin/blp-server as a script...
Shelling out in Unix system with ['sh', '/usr/local/Cellar/bloop/1.4.0-RC1/bin/blp-server']
Detected java options are ''
Unable to find any JVMs matching version "1.8".
No Java runtime present, requesting install.
Bloop server in /usr/local/Cellar/bloop/1.4.0-RC1/bin/blp-server failed to run.
First invocation attempt: ['java', '-jar', '/usr/local/Cellar/bloop/1.4.0-RC1/bin/blp-server']
-> Return code: 1
Second invocation attempt: ['sh', '/usr/local/Cellar/bloop/1.4.0-RC1/bin/blp-server']
-> Return code: 2
➜  ~ java -version
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.232-b09, mixed mode)
➜  ~ echo $JAVA_HOME
/Users/jules.ivanic/.sdkman/candidates/java/current

When, I'm launching the bloop server command the following Macos popup shows up:

Screenshot 2020-01-21 12 09 19

I installed the JDK with SDKMAN (https://sdkman.io/). My JAVA_HOME is correctly set.

How can I fix that?

Thanks, Jules

jvican commented 4 years ago

Thanks for reporting @guizmaii. This issue happens because /usr/libexec/java_home doesn't support sdkman. @ahjohannessen has also reported the same issue in Discord.

I plan to fix this by getting rid of java_home in the macOS brew formula so that we don't force JDK 8 on macOS. This is a thing inherited from the past where bloop didn't support JDK 11 and where I was wary of supporting JDK 11 over JDK 8 because it produces slower compilation. That will change in the release of v1.4.0.

jimmycuadra-stripe commented 4 years ago

I'm guessing it's the same underlying issue, but I get similar output trying to run bloop server and I'm not using sdkman, nor is $JAVA_HOME set. I also have JDK 13.

$ bloop server
Defaulting on nailgun port 8212
There is no server running at port 8212
Starting the bloop server... this may take a few seconds
Running /usr/local/Cellar/bloop/1.4.0-RC1/bin/blp-server as a jar...
Shelling out with '['java', '-jar', '/usr/local/Cellar/bloop/1.4.0-RC1/bin/blp-server']' ...
Error: Invalid or corrupt jarfile /usr/local/Cellar/bloop/1.4.0-RC1/bin/blp-server
Running /usr/local/Cellar/bloop/1.4.0-RC1/bin/blp-server as a script...
Shelling out in Unix system with ['sh', '/usr/local/Cellar/bloop/1.4.0-RC1/bin/blp-server']
Detected java options are ''
Unable to find any JVMs matching version "1.8".
Bloop server in /usr/local/Cellar/bloop/1.4.0-RC1/bin/blp-server failed to run.
First invocation attempt: ['java', '-jar', '/usr/local/Cellar/bloop/1.4.0-RC1/bin/blp-server']
-> Return code: 1
Second invocation attempt: ['sh', '/usr/local/Cellar/bloop/1.4.0-RC1/bin/blp-server']
-> Return code: 2
$ java -version
openjdk version "13.0.1" 2019-10-15
OpenJDK Runtime Environment AdoptOpenJDK (build 13.0.1+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 13.0.1+9, mixed mode, sharing)
$ echo $JAVA_HOME

Note the lack of "No Java runtime present, requesting install." and GUI popup as described in the OP.

jvican commented 4 years ago

JDK 13 is not supported, please check docs for more info.

jsatk commented 4 years ago

I'm also seeing this "Invalid or corrupt jarfile" warning. As far as I can tell everything is working fine though.

Defaulting on nailgun port 8212
There is no server running at port 8212
Starting the bloop server... this may take a few seconds
Running /usr/local/Cellar/bloop/1.4.0-RC1/bin/blp-server as a jar...
Shelling out with '['java', '-jar', '/usr/local/Cellar/bloop/1.4.0-RC1/bin/blp-server']' ...
Error: Invalid or corrupt jarfile /usr/local/Cellar/bloop/1.4.0-RC1/bin/blp-server
Running /usr/local/Cellar/bloop/1.4.0-RC1/bin/blp-server as a script...
Shelling out in Unix system with ['sh', '/usr/local/Cellar/bloop/1.4.0-RC1/bin/blp-server']
Detected java options are ''
Unable to load nailgun-version.properties.
NGServer [UNKNOWN] started on address localhost/127.0.0.1 port 8212.
jvican commented 4 years ago

Don't worry about that, that's expected, it's a bening error

jvican commented 4 years ago

It's an error that will be gone in the next release btw @jsatk it's caused by the python client that starts up the server

guizmaii commented 4 years ago

@jvican Does this PR https://github.com/scalacenter/bloop/pull/1196 fix the problem reported here?

jvican commented 4 years ago

Yup, the launcher should already be working on these environments. Our next release deprecates the bloop python client that you are currently using and will use the launcher exclusively, which means both of these issues will be gone in 1.4.0

guizmaii commented 4 years ago

Yup, the launcher should already be working on these environments.

Screenshot 2020-03-25 10 41 30

Maybe I misunderstood what you mean by "the launcher should already be working on these environments". 🤔

jsatk commented 4 years ago

It's an error that will be gone in the next release btw @jsatk it's caused by the python client that starts up the server

Thanks for the explanation @jvican.

When I see scary errors I tend to think I've done something wrong 😆.

jvican commented 4 years ago

@guizmaii Yes, that is not the launcher, that is the installer. Long story short, bloop 1.4.0 will update the installation methods so that you don't see that anymore! Will elaborate more on this point in the release notes

@jsatk That's a totally reasonable expectation, I agree the script should not be showing that error when it's benign.

igor-ramazanov commented 4 years ago

Am I right that the workaround for now if I must have JDK11 locally would be as follows: 1) Clone the project (since the fix is already there, just haven't been published yet) 2) Switch to JDK8 3) Build bloop and then install it locally 4) Switch to JDK11 5) Start compiling projects using bloop + JDK11 ?

olafurpg commented 4 years ago

@igor-ramazanov Since https://github.com/scalacenter/bloop/pull/1203 you can globally configure the Java version for bloop in $HOME/.bloop/bloop.json. Docs https://scalacenter.github.io/bloop/docs/server-reference#custom-java-home

This option is respected regardless if you use bloopgun (the new bloop cli), Metals or IntelliJ

igor-ramazanov commented 4 years ago

@olafurpg Thank you so much for the quick answer! I haven't tried it yet, but will do tomorrow and let you know if it works out. Thank you and stay healthy ✊

guizmaii commented 4 years ago

@olafurpg Is it normal that when I configure the custom java home is the bloop.json, I still have this problem: https://github.com/scalacenter/bloop/issues/1150#issuecomment-603561109?

olafurpg commented 4 years ago

I have never seen that message. The custom java home is only respected in the latest nightly build, the homebrew is older. How are you launching bloop?

guizmaii commented 4 years ago

brew start bloop

olafurpg commented 4 years ago

The brew formula is using an old Bloop version. You can start a Bloop server with the latest version like this

brew services stop bloop
bloop exit
cs launch ch.epfl.scala:bloopgun-core_2.12:1.4.0-RC1-162-888454e1 -- help
bloop help
igor-ramazanov commented 4 years ago

@olafurpg I tried the #1204 (not thoroughly) and failed to properly setup it having the same couldn't find JDK 1.8 error. I wrote personal bash scripts using coursier to run bloop as you showed in the above message.

zingmane commented 3 years ago

Setting $HOME/.bloop/bloop.json hasn't worked for me (macOS)

But that fixed it:

> bloop about
bloop v1.4.4

Using Scala v2.12.8 and Zinc v1.3.0-M4+45-d4354be3
Running on Java JDK v11.0.2 (/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home)
  -> Supports debugging user code, Java Debug Interface (JDI) is available.
Maintained by the Scala Center (Jorge Vicente Cantero, Martin Duhem)
gdxn96 commented 3 years ago

I followed your steps and it also fixed my issues @zingmane thank you!

tgodzik commented 1 month ago

I don't think this is still relevant, we can open a specific issue if the new behaviour is not working