I have a play project, and I want to add an sbt task that runs the application with a given folder available as a resource. However, I don't want that folder to be on the classpath during "normal" runs.
I created a configuration, added the resources to that configuration, but when I run in that configuration, the files aren't being picked up
for example, I have:
val Mock = config(“mock”) extend Compile
val mock = inputKey[Unit]("run in mock mode")
val project = Project(“my project”, file(“src/”))
.configs(Mock)
.settings(
unmanagedResourceDirectories in Mock ++= Seq(baseDirectory.value / “mock-resources”)
mock <<= run in Mock
)
I want it so that when I type mock
the mock-resources
is on the classpath, and when i type run
it isn't.
I'm using play 2.2.0 with sbt 0.13.1
You need to set the appropriate settings and tasks that are under
Compile
configuration to the newly-definedMock
configuration. The reason for this is this:When there's no setting or task under
Mock
sbt keeps searching inCompile
whererun
is indeed defined but usesCompile
values.Do the following and it's going to work - note
Classpaths.configSettings
andrun
inSeq
:NOTE I'm unsure why I needed the following line:
My guess is that because
run
usesfullClasspath
that defaults toCompile
scope it doesn't see the value inMock
. sbt keeps amazing me!I've asked about it in Why does the default run task not pick settings in custom configuration?
Sample
I've been running the build with the following
hello.scala
undersrc
directory:Upon
p/mock:mock
it gave me:Same for
p/mock:run
:And
mock
was no different: