VirtusLab / scala-cli

Scala CLI is a command-line tool to interact with the Scala language. It lets you compile, run, test, and package your Scala code (and more!)
https://scala-cli.virtuslab.org
Apache License 2.0
554 stars 129 forks source link

Error downloading bloop 2.0.0 with Java 21 #3315

Open mbovel opened 2 days ago

mbovel commented 2 days ago

Version(s)

➜  ~/scala-snippets-6 scala -version
Scala code runner version: 1.4.3
Scala version (default): 3.5.1

Describe the bug After switching to Java 21, scala fails to run because it tries to download non-existing 2.0.0 version of Bloop from https://repo1.maven.org/maven2/io/github/alexarchambault/bleep/bloop-frontend_2.12/2.0.0/bloop-frontend_2.12-2.0.0.pom.

To Reproduce

➜  ~/scala-snippets-6 coursier java --jvm adoptium:17 --setup
Checking if ~/.profile, ~/.zprofile need(s) updating.
Some shell configuration files were updated. It is recommended to close this terminal once the setup command is done, and open a new one for the changes to be taken into account.
➜  ~/scala-snippets-6 source ~/.zprofile
➜  ~/scala-snippets-6 java -version
openjdk version "17.0.13" 2024-10-15
OpenJDK Runtime Environment Temurin-17.0.13+11 (build 17.0.13+11)
OpenJDK 64-Bit Server VM Temurin-17.0.13+11 (build 17.0.13+11, mixed mode)
➜  ~/scala-snippets-6 scala hello.scala                      
Compiling project (Scala 3.5.1, JVM (17))
Compiled project (Scala 3.5.1, JVM (17))
hello
➜  ~/scala-snippets-6 coursier java --jvm adoptium:21 --setup
Checking if ~/.profile, ~/.zprofile need(s) updating.
Some shell configuration files were updated. It is recommended to close this terminal once the setup command is done, and open a new one for the changes to be taken into account.
➜  ~/scala-snippets-6 source ~/.zprofile                     
➜  ~/scala-snippets-6 java -version                          
openjdk version "21.0.5" 2024-10-15 LTS
OpenJDK Runtime Environment Temurin-21.0.5+11 (build 21.0.5+11-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.5+11 (build 21.0.5+11-LTS, mixed mode)
➜  ~/scala-snippets-6 scala hello.scala                      
Downloading compilation server 2.0.0
Error: java.lang.Exception: Error getting Bloop class path
For more details, please see '/Users/mbovel/scala-snippets-6/.scala-build/stacktraces/1732530469-3770255878123996869.log'
➜  ~/scala-snippets-6 scala --server=false hello.scala
hello
➜  ~/scala-snippets-6 cat .scala-build/stacktraces/1732530469-3770255878123996869.log
java.lang.Exception: Error getting Bloop class path
  bloop.rifle.BloopRifle$.startServer(BloopRifle.scala:49)
  bloop.rifle.BloopServer$.startBloop$1(BloopServer.scala:77)
  bloop.rifle.BloopServer$.ensureBloopRunning(BloopServer.scala:108)
  bloop.rifle.BloopServer$.bsp(BloopServer.scala:155)
  bloop.rifle.BloopServer$.buildServer(BloopServer.scala:185)
  scala.build.compiler.BloopCompilerMaker.$anonfun$1(BloopCompilerMaker.scala:48)
  scala.build.compiler.BloopCompiler.<init>(BloopCompiler.scala:15)
  scala.build.compiler.BloopCompilerMaker.$anonfun$2(BloopCompilerMaker.scala:51)
  scala.util.Try$.apply(Try.scala:217)
  scala.build.compiler.BloopCompilerMaker.create(BloopCompilerMaker.scala:51)
  scala.build.compiler.ScalaCompilerMaker.withCompiler(ScalaCompilerMaker.scala:34)
  scala.build.compiler.ScalaCompilerMaker.withCompiler$(ScalaCompilerMaker.scala:9)
  scala.build.compiler.BloopCompilerMaker.withCompiler(BloopCompilerMaker.scala:14)
  scala.build.Build$.build$$anonfun$3(Build.scala:616)
  scala.build.EitherCps$Helper.apply(EitherCps.scala:19)
  scala.build.Build$.build(Build.scala:619)
  scala.cli.commands.run.Run$.runCommand(Run.scala:332)
  scala.cli.commands.default.Default.runCommand(Default.scala:61)
  scala.cli.commands.default.Default.runCommand(Default.scala:40)
  scala.cli.commands.ScalaCommand.run(ScalaCommand.scala:388)
  scala.cli.commands.ScalaCommand.run(ScalaCommand.scala:369)
  caseapp.core.app.CaseApp.main(CaseApp.scala:157)
  scala.cli.commands.ScalaCommand.main(ScalaCommand.scala:354)
  caseapp.core.app.CommandsEntryPoint.main(CommandsEntryPoint.scala:169)
  scala.cli.ScalaCliCommands.main(ScalaCliCommands.scala:125)
  scala.cli.ScalaCli$.main0(ScalaCli.scala:295)
  scala.cli.ScalaCli$.main(ScalaCli.scala:119)
  scala.cli.ScalaCli.main(ScalaCli.scala)
scala.build.errors.FetchingDependenciesError: Error downloading io.github.alexarchambault.bleep:bloop-frontend_2.12:2.0.0
  No fallback URL found
  not found: /Users/mbovel/.ivy2/local/io.github.alexarchambault.bleep/bloop-frontend_2.12/2.0.0/ivys/ivy.xml
  not found: https://repo1.maven.org/maven2/io/github/alexarchambault/bleep/bloop-frontend_2.12/2.0.0/bloop-frontend_2.12-2.0.0.pom
  scala.build.Artifacts$.toFetchingDependenciesError(Artifacts.scala:704)
  scala.build.Artifacts$.fetchCsDependencies$$anonfun$1$$anonfun$2(Artifacts.scala:678)
  scala.util.Either$LeftProjection.map(Either.scala:622)
  scala.build.Artifacts$.fetchCsDependencies$$anonfun$1(Artifacts.scala:680)
  scala.build.EitherCps$Helper.apply(EitherCps.scala:19)
  scala.build.Artifacts$.fetchCsDependencies(Artifacts.scala:682)
  scala.build.Artifacts$.fetchAnyDependenciesWithResult$$anonfun$1(Artifacts.scala:571)
  scala.build.EitherCps$Helper.apply(EitherCps.scala:19)
  scala.build.Artifacts$.fetchAnyDependenciesWithResult(Artifacts.scala:588)
  scala.build.Artifacts$.fetchAnyDependencies$$anonfun$1(Artifacts.scala:536)
  scala.build.EitherCps$Helper.apply(EitherCps.scala:19)
  scala.build.Artifacts$.fetchAnyDependencies(Artifacts.scala:540)
  scala.build.Artifacts$.artifacts$$anonfun$1(Artifacts.scala:467)
  scala.build.EitherCps$Helper.apply(EitherCps.scala:19)
  scala.build.Artifacts$.artifacts(Artifacts.scala:487)
  scala.build.Bloop$.bloopClassPath$$anonfun$1(Bloop.scala:74)
  scala.build.EitherCps$Helper.apply(EitherCps.scala:19)
  scala.build.Bloop$.bloopClassPath(Bloop.scala:83)
  scala.build.Bloop$.bloopClassPath$$anonfun$2(Bloop.scala:105)
  scala.build.EitherCps$Helper.apply(EitherCps.scala:19)
  scala.build.Bloop$.bloopClassPath(Bloop.scala:108)
  scala.cli.commands.shared.SharedCompilationServerOptions.$anonfun$13(SharedCompilationServerOptions.scala:264)
  bloop.rifle.BloopRifle$.startServer(BloopRifle.scala:48)
  bloop.rifle.BloopServer$.startBloop$1(BloopServer.scala:77)
  bloop.rifle.BloopServer$.ensureBloopRunning(BloopServer.scala:108)
  bloop.rifle.BloopServer$.bsp(BloopServer.scala:155)
  bloop.rifle.BloopServer$.buildServer(BloopServer.scala:185)
  scala.build.compiler.BloopCompilerMaker.$anonfun$1(BloopCompilerMaker.scala:48)
  scala.build.compiler.BloopCompiler.<init>(BloopCompiler.scala:15)
  scala.build.compiler.BloopCompilerMaker.$anonfun$2(BloopCompilerMaker.scala:51)
  scala.util.Try$.apply(Try.scala:217)
  scala.build.compiler.BloopCompilerMaker.create(BloopCompilerMaker.scala:51)
  scala.build.compiler.ScalaCompilerMaker.withCompiler(ScalaCompilerMaker.scala:34)
  scala.build.compiler.ScalaCompilerMaker.withCompiler$(ScalaCompilerMaker.scala:9)
  scala.build.compiler.BloopCompilerMaker.withCompiler(BloopCompilerMaker.scala:14)
  scala.build.Build$.build$$anonfun$3(Build.scala:616)
  scala.build.EitherCps$Helper.apply(EitherCps.scala:19)
  scala.build.Build$.build(Build.scala:619)
  scala.cli.commands.run.Run$.runCommand(Run.scala:332)
  scala.cli.commands.default.Default.runCommand(Default.scala:61)
  scala.cli.commands.default.Default.runCommand(Default.scala:40)
  scala.cli.commands.ScalaCommand.run(ScalaCommand.scala:388)
  scala.cli.commands.ScalaCommand.run(ScalaCommand.scala:369)
  caseapp.core.app.CaseApp.main(CaseApp.scala:157)
  scala.cli.commands.ScalaCommand.main(ScalaCommand.scala:354)
  caseapp.core.app.CommandsEntryPoint.main(CommandsEntryPoint.scala:169)
  scala.cli.ScalaCliCommands.main(ScalaCliCommands.scala:125)
  scala.cli.ScalaCli$.main0(ScalaCli.scala:295)
  scala.cli.ScalaCli$.main(ScalaCli.scala:119)
  scala.cli.ScalaCli.main(ScalaCli.scala)
coursier.error.ResolutionError$CantDownloadModule: Error downloading io.github.alexarchambault.bleep:bloop-frontend_2.12:2.0.0
  No fallback URL found
  not found: /Users/mbovel/.ivy2/local/io.github.alexarchambault.bleep/bloop-frontend_2.12/2.0.0/ivys/ivy.xml
  not found: https://repo1.maven.org/maven2/io/github/alexarchambault/bleep/bloop-frontend_2.12/2.0.0/bloop-frontend_2.12-2.0.0.pom
  coursier.Resolve$.$anonfun$validate$1(Resolve.scala:392)
  scala.collection.immutable.List.map(List.scala:247)
  scala.collection.immutable.List.map(List.scala:79)
  coursier.Resolve$.validate(Resolve.scala:390)
  coursier.Resolve.validate0$1(Resolve.scala:151)
  coursier.Resolve.$anonfun$ioWithConflicts0$4(Resolve.scala:201)
  coursier.util.Task$.$anonfun$flatMap$extension$1(Task.scala:14)
  coursier.util.Task$.$anonfun$flatMap$extension$1$adapted(Task.scala:14)
  coursier.util.Task$.wrap(Task.scala:82)
  coursier.util.Task$.$anonfun$flatMap$2(Task.scala:14)
  scala.concurrent.impl.Promise$Transformation.run(Promise.scala:470)
  java.base@17.0.6/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
  java.base@17.0.6/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
  java.base@17.0.6/java.lang.Thread.run(Thread.java:833)
  com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:775)
  com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:203)

Expected behaviour No crash, like with Java 17.

tgodzik commented 2 days ago

Thanks for reporting, that should be impossible :thinking: Earlier versions of Scala CLI should just use older bloop versions. @Gedochao any idea how this happens? I think it did happen previously.

Gedochao commented 2 days ago

Thanks for reporting, that should be impossible 🤔 Earlier versions of Scala CLI should just use older bloop versions. @Gedochao any idea how this happens? I think it did happen previously.

No idea, but I'll check

Gedochao commented 1 day ago

@mbovel Does it keep happening after running:

scala-cli bloop exit --power

?

Is there anything interesting when:

scala-cli bloop output --power

?

Also, what platform is this happening on? I can't seem to be able to reproduce on my local machine. I've no clue how the old Bloop fork dependency gets messed up with the newest Bloop version. 😕

mbovel commented 1 day ago

I cannot reproduce today 🤷

It now works fine, even when switching from 17 to 21 without explicitly killing the server:


➜  ~/scala-snippets-6 coursier java --jvm adoptium:17 --setup
Checking if ~/.profile, ~/.zprofile need(s) updating.
Some shell configuration files were updated. It is recommended to close this terminal once the setup command is done, and open a new one for the changes to be taken into account.
➜  ~/scala-snippets-6 source ~/.zprofile                     
➜  ~/scala-snippets-6 scala-cli bloop exit --power           
Stopped Bloop server.
➜  ~/scala-snippets-6 java -version
openjdk version "17.0.13" 2024-10-15
OpenJDK Runtime Environment Temurin-17.0.13+11 (build 17.0.13+11)
OpenJDK 64-Bit Server VM Temurin-17.0.13+11 (build 17.0.13+11, mixed mode)
➜  ~/scala-snippets-6 scala hello.scala                      
Starting compilation server
hello
➜  ~/scala-snippets-6 coursier java --jvm adoptium:21 --setup
Checking if ~/.profile, ~/.zprofile need(s) updating.
Some shell configuration files were updated. It is recommended to close this terminal once the setup command is done, and open a new one for the changes to be taken into account.
➜  ~/scala-snippets-6 source ~/.zprofile                     
➜  ~/scala-snippets-6 java -version                          
openjdk version "21.0.5" 2024-10-15 LTS
OpenJDK Runtime Environment Temurin-21.0.5+11 (build 21.0.5+11-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.5+11 (build 21.0.5+11-LTS, mixed mode)
➜  ~/scala-snippets-6 scala hello.scala                      
Starting compilation server
hello
➜  ~/scala-snippets-6 scala-cli bloop output --power
Bloop server PID: 81239
Ignoring SIGINT
Will truncate output file /Users/mbovel/Library/Caches/ScalaCli/bloop/daemon/output every 5 minutes
Unable to load nailgun-version.properties.
NGServer [UNKNOWN] started on local socket /Users/mbovel/Library/Caches/ScalaCli/bloop/daemon/socket.
mbovel commented 1 day ago

I am on a MacBook Pro 2.6 GHz 6-Core Intel Core i7.

mbovel commented 1 day ago

Ah, got it again!

The output of scala-cli bloop output --power (but it doesn't seem related):

bloop_output.txt

➜  ~/scala-snippets-6 scala-cli bloop output --power > bloop_output.txt
➜  ~/scala-snippets-6 scala-cli bloop exit --power                     
Stopped Bloop server.
➜  ~/scala-snippets-6 scala hello.scala                   
Starting compilation server
Compiling project (Scala 3.5.1, JVM (21))
[E] Caught java.lang.InterruptedException
Bloop 'bsp' command exited with code 1. Something may be wrong with the current configuration.
Running the clean sub-command to clear the working directory and remove caches might help.
If the error persists, please report the issue as a bug and attach a log with increased verbosity by passing -v -v -v.

^C%                                                                                                                                                          
➜  ~/scala-snippets-6 pkill java
➜  ~/scala-snippets-6 scala hello.scala
Downloading compilation server 2.0.0
Error: java.lang.Exception: Error getting Bloop class path
For more details, please see '/Users/mbovel/scala-snippets-6/.scala-build/stacktraces/1732650920-11351170908216290531.log'
➜  ~/scala-snippets-6 scala-cli bloop exit --power  
No running Bloop server found.
➜  ~/scala-snippets-6 scala hello.scala
Starting compilation server
hello
mbovel commented 1 day ago

And interleaved failures and successes:

➜  ~/scala-snippets-6 scala hello.scala
Downloading compilation server 2.0.0
Error: java.lang.Exception: Error getting Bloop class path
For more details, please see '/Users/mbovel/scala-snippets-6/.scala-build/stacktraces/1732651242-15625038165421289792.log'
➜  ~/scala-snippets-6 scala hello.scala
Starting compilation server
hello
➜  ~/scala-snippets-6 scala hello.scala
hello
➜  ~/scala-snippets-6 scala hello.scala
hello
➜  ~/scala-snippets-6 scala hello.scala
hello
➜  ~/scala-snippets-6 scala hello.scala
Downloading compilation server 2.0.0
Error: java.lang.Exception: Error getting Bloop class path
For more details, please see '/Users/mbovel/scala-snippets-6/.scala-build/stacktraces/1732651287-10082150269091005545.log'
➜  ~/scala-snippets-6 scala hello.scala
Starting compilation server
hello
➜  ~/scala-snippets-6 scala hello.scala
hello
➜  ~/scala-snippets-6 scala hello.scala
Downloading compilation server 2.0.0
Error: java.lang.Exception: Error getting Bloop class path
For more details, please see '/Users/mbovel/scala-snippets-6/.scala-build/stacktraces/1732651311-1525226576094307270.log'

It seems that this came from an interaction between compiling from the CLI and from Metals. After Metals compiled my code, I got the error from the CLI.

Maybe Metals passed some outdated options to Bloop?

After removing .scala-build, .bsp, .metals, I cannot reproduce the issue anymore, so this seems to be it.

tgodzik commented 23 hours ago

What version of metals do you have? Maybe Metals is picking up older scala-cli binary and that is somehow breaking (maybe both scala and scala-cli are on path)? Do you have bloopVersion set explicitly in Metals? If you only run via scala-cli there is no direct interaction between metals and Bloop, so Metals is not actually downloading anything.

The weirdest thing is the organization is not cached anywhere as far as I can tell.

tgodzik commented 23 hours ago

Also, could you paste the contents of your .bsp and .scala-build <- any non bloop json files there. Maybe we are indeed caching something there?