'SBT gives my Scala program stale resource files
I have a simple Scala project using SBT. I have a resource file, src/main/resources/cea-builtins.rkt. I open it with val resource = Source.fromResource("cea-builtins.rkt").
Unfortunately, it gives me a stale version of the resource file.
What I expect to happen is:
- I edit the file.
- I run my program from the sbt command prompt and my program reads the updated file.
What actually happens is:
- I edit the resource file.
- I run my program from the sbt command prompt and my program reads the old version of the file.
I can clean the project and still get the old version of the file.
If I exit SBT, restart it, and then run my program, I get the updated version of the resource file.
I note that there is a copy of the file in ./target/scala-2.13/<project_name>_2.13-0.1.jar. Updating the resource file and running the program causes that copy to be updated, but I still get the old contents in my program.
If I do lsof -p <sbt_pid> | grep <project_name> I get
<project_root>/target/bg-jobs/sbt_ae437a1d/job-1/target/c224367f/577d7b48/<project_name>_2.13-0.1.jar
I wondered if my program was getting a copy from that file, but that file does not exist in spite of what lsof says.
I've been using Source.fromResource("cea-builtins.rkt") to read the file. That works (except that it's stale). However, if I adapt my code to open the resource with getClass.getResource("cea-builtins.rkt") it fails, as this returns null. I don't understand why.
My build.sbt file is absolutely vanilla. It does not change any paths. It contains library dependencies, one resolver, and that's about it. The only plugin is sbt-assembly.
Any help understanding why I get the stale resource unless I exit and restart SBT? Any suggestions on how to fix this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
