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

Resources file not visible in classes directory #1631

Open lwronski opened 2 years ago

lwronski commented 2 years ago

Hello, I have an issue with bloop run, that resource files are not copied to the classes directory.

Using this source:

$ cat src/main/resources
1 2 3 4
$ cat src/main/scala/Main.scala
import scala.io.Source

object Main extends App {
  val inputs = Source.fromResource("input").getLines.toSeq
  println(inputs.mkString(""))
}

With SBT:

$ sbt run
...
$ ls target/scala-2.13/classes/
Main$.class                     Main.class
Main$delayedInit$body.class     input

classes directory contains input file

With bloop:

After running sbt bloopInstall

$ bloop compile hello-world
...
$ ls .bloop/hello-world/bloop-internal-classes/classes-Metals-V0ZUSdL_Q7KLGmw0GcCopw\=\=-NfPLLT32T_C-HitNIi5aLQ\=\=/
META-INF                        Main$delayedInit$body.class
Main$.class                     Main.class

but with bloop classes directory doesn't contain input file

tgodzik commented 2 years ago

Thanks for reporting! We might not be correctly copying the results to the client class directories.

Arthurm1 commented 2 years ago

As far as I understand - Bloop intentionally doesn't copy resources into the classes dir. Instead it puts the resources dir on the classpath (and expects it to be on the classpath of dependent projects). I guess this is an optimisation to save on file copying. This works fine for compile/test/run but not packaging. It might be easier to change the package code to include the resources dir.

tgodzik commented 2 years ago

Thanks for pointing that out! Bloop wasn't doing any packaging yet, so that would explain it.

kpodsiad commented 2 years ago

@tgodzik It's worth noting that the issue is not about packaging, @lwronski provided an example with sbt run which compiles and runs code.

For me, the main issue is that once compiled stuff shouldn't change its behavior. If bloop puts current resources from the working directory on the classpath then after compilation I may do some changes in resources. Suddenly the program is working differently and it could be very hard to spot why.

Every build tool which I know is copying resources and I expect that Bloop behaves similarly.