scalameta / metals

Scala language server with rich IDE features 🚀
https://scalameta.org/metals/
Apache License 2.0
2.09k stars 330 forks source link

Run main: sbt dependencies with Runtime scope are missing from classpath #4950

Open aumann opened 1 year ago

aumann commented 1 year ago

Describe the bug

I've just noticed this with a project using slf4j, with logback being on the runtime classpath.

val slf4j           = "org.slf4j"      % "slf4j-api"       % "2.0.3"
val logback         = "ch.qos.logback" % "logback-classic" % "1.3.3" % Runtime

Now, when I run the program from VS Code I get the "no providers found" message:

SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.

Everything works as expected if I execute sbt run

I've taken a look at the "*.metals-buildtarget" file, and logback isn't there either.

If I add logback to the compile scope everything works as expected. This is mostly a "nice to have" for this project of mine, but there may be cases where this is more surprising and harder to diagnose.

Expected behavior

Runtime dependencies should be on the classpath when the program is run.

Edit: Note that logback is on the test classpath - running tests works as expected

Operating system

Windows

Editor/Extension

VS Code

Version of Metals

0.11.10

Extra context or search terms

Let me know if I should provide a minimized project. I just wanted to open the issue first - maybe it's obvious or known, and there is something I can change on my side.

The doctor shows all green checkboxes for the project.

Build server currently being used is Bloop v1.5.6.

Metals Java: 11.0.8 from AdoptOpenJDK located at C:\Program Files\Java\jdk-11-hotspot

Metals Server version: 0.11.10
tgodzik commented 1 year ago

Thanks for reporting! Looks like we are not setting the correct classpath in the Bloop sbt plugin, this might need a fix upstream in Bloop.

tgodzik commented 1 year ago

Just FYI there is an upstream issue that we haven't worked on yet https://github.com/scalacenter/bloop/pull/1387