SBT 1.0.1+ fails on loading resources
See original GitHub issueScala code to list resources which works in sbt 0.13.x and SBT 1.0.0 fails in SBT 1.0.1 and 1.1.1
steps
- Clone this project https://github.com/jdrphillips/sbt-testing
- Run
sbt "run /subfolder"
Direct link to the code being run: https://github.com/jdrphillips/sbt-testing/blob/master/src/main/scala/foo/Testing.scala
To see a working version using sbt 0.13.17, checkout the branch 1317
on the same project and complete the same steps. To see SBT 1.0.0, checkout branch 100
. The code being run does not change between branches.
The code fails on branches 111
(SBT 1.1.1) and 101
(SBT 1.0.1)
problem
When trying to load resources in SBT 1.0.1+ using getClass.getResource
, the path generated is something like:
file:/tmp/sbt_2a66a2c6/job-1/target/84311835/sbt-testing_2.12-0.1-SNAPSHOT.jar!/subfolder
when it should be something like:
~/sbt-testing/target/scala-2.12/classes/subfolder
This change has the effect of being unable to list files in a resource directory. java.io.File
cannot find the first path.
expectation
The scala code which runs on the 1317
branch should also run on the 111
and 101
branches (sbt versions 1.1.1
and 1.0.1
respectively).
notes
scala version 2.12.4
sbt version: 1.1.1
, 1.0.1
Confirmed behaviour on Ubuntu and Mac.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:15 (5 by maintainers)
Top GitHub Comments
Can someone explain why is this marked as closed but the problem still presists in SBT 1.2.6? Whenever I use
getClass.getResource
in my code I cannot usesbt run
because it’ll fail to find the files, this makessbt run
basically unusable. I couldn’t even find any workarounds to this. Suggestions?This is still an issue, and should be reopened. You can add the following to your
build.sbt
as a temporary solution:run := Defaults.runTask(fullClasspath in Runtime, mainClass in run in Compile, runner in run).evaluated