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
907 stars 202 forks source link

Dependencies from Runtime configuration are not visible #1606

Open eikek opened 2 years ago

eikek commented 2 years ago

Hello! I have an issue with bloop run … in one of my projects where it seems that dependencies that are declrared in sbts Runtime config are not visible. I prepared a small example project to reproduce it. Thank you very much!

Using this source:

package bloop.demo

object Main {
  def main(args: Array[String]): Unit = {
    println(">>> hello world! <<<")
    val cn = Class.forName("ch.qos.logback.classic.Logger")
    println(s"$cn")
  }
}

Where the logback dependency is declared for the Runtime configuration.

With SBT:

$ sbt run
[info] welcome to sbt 1.5.5 (Oracle Corporation Java 11.0.12)
[info] loading settings for project bloop-demo-build from plugins.sbt ...
[info] loading project definition from /home/eike/workspace/bloop-demo/project
[info] loading settings for project bloop-demo from build.sbt ...
[info] set current project to bloop-demo (in build file:/home/eike/workspace/bloop-demo/)
[info] compiling 1 Scala source to /home/eike/workspace/bloop-demo/target/scala-2.12/classes ...
[info] running bloop.demo.Main
>>> hello world! <<<
class ch.qos.logback.classic.Logger
[success] Total time: 3 s, completed 12 Nov 2021, 17:44:30

With bloop:

After running sbt bloopInstall

$ bloop run bloop-demo
Compiling bloop-demo (1 Scala source)
Compiled bloop-demo (292ms)
>>> hello world! <<<
[E] Exception in thread "main" java.lang.ClassNotFoundException: ch.qos.logback.classic.Logger
[E]     at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
[E]     at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
[E]     at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
[E]     at java.base/java.lang.Class.forName0(Native Method)
[E]     at java.base/java.lang.Class.forName(Class.java:315)
[E]     at bloop.demo.Main$.main(Main.scala:6)
[E]     at bloop.demo.Main.main(Main.scala)

bloop-demo.tar.gz

tgodzik commented 2 years ago

Thanks for reporting! Looks like we never did https://github.com/scalacenter/bloop/pull/1387 for sbt, so we should be able to add it for the sbt integration.

igor-ramazanov commented 1 year ago

I'm trying to be disciplined with the dependencies using an sbt plugin https://github.com/cb372/sbt-explicit-dependencies.

The plugin can report nice messages about unused and undeclared compile time dependencies.

However, if you probably will want to exclude certain dependencies like for logging or Netty, because they do not appear in your source code directly, for example, if you use this plugin in CI.

The proper way of doing this is by marking the dependencies' scope such as % Runtime, % Test.

The current workaround is to use the unusedCompileDependenciesFilter -= moduleFilter("org.scalaz", "scalaz") setting from the plugin to explicitly ignore some dependencies from the report, however, it's not very ideal.