Search code examples
sbtspraysbt-revolver

Custom resourceDirectory for Revolver/Spray


I have a Spray application with a basic front end component with source in src/main/frontend and the deployed version (compiled sass, minification etc.) in Spray's default resources location src/main/resources. I would like to change the resource directory to src/main/frontend for Revolver's re-start task only, in order to see changes quicker when developing.

I have tried adding the setting

resourceDirectory in Revolver.reStart <<= baseDirectory(_ / "src" / "main" / "frontend")

but it doesn't seem to have an effect. I guess because resourceDirectory is a setting in the Compile scope and not one in Revolver itself. In the SBT console:

> reStart:resourceDirectory
[info] /Users/cartew01/workspace/applaudio-spray/src/main/frontend
> compile:resourceDirectory
[info] /Users/cartew01/workspace/applaudio-spray/src/main/resources

Does anyone know how I can change this for the re-start task but not for any others? Possibly by creating a custom task that calls re-start with the additional setting?

Thank you for your help.


Solution

  • You should add your another resource directory to the fullClasspath in reStart, for instance (fullClasspath in Revolver.reStart) += (WebKeys.public in Assets in web).value, or in your case fullClasspath in Revolver.reStart += baseDirectory(_ / "src" / "main" / "frontend") - actually, getFromResourceDirectory and getFromResource will serve contents from the class path.

    to better understand it, i suggest running inspect reStart - it depends on compile:products, which in turn depends on compile:copyResources, which in turn depends on compile:resourceDirectories. So, reStart will use whatever is produced by compiler, i.e. resources copied from somewhere. The solution above seems a bit easier