scalasbtsbt-revolver

Can I make sbt compile additional sources with additional dependencies only for a specific task?


I am using spray revolver to test my application while writting code.

I would like to make a revolver run compile additional sources (e.g. /src/dev.scala or whatever) with additional dependencies. This is so when testing locally I can startup some external sevices we are using (e.g. cassandra) in the same vm without the need to have a proper environment set up.

Initially I tried setting these settings like this:

unmanagedSources in Revolver.reStart <<= (unmanagedSources in Compile) map { ss => ss :+ new File("/path/to/my/dev.scala") }

libraryDependencies in Revolver.reStart += ("org.cassandraunit" % "cassandra-unit" % "2.0.2.1")

mainClass in Revolver.reStart := Some("my.main.class.in.dev")

But when running the task,I just get that the main class doesn't exist.

Is there any way to make this work? The idea is to avoid having the cassandra-unit and code in dev.scala out of the compilation for tests & packaging.


Solution

  • That cannot work, because Revolver.reStart still uses compile in Compile, and compile in Compile uses libraryDependencies, not libraryDependencies in Revolver.reStart.

    To do this, you need to defined an entirely different, custom configuration that extends your Compile configuration. In that configuration, say "Localcompile", you can define your dependency with

    unmanagedSources in Localcompile += new File("/path/to/my/dev.scala")
    
    libraryDependencies += "org.cassandraunit" % "cassandra-unit" % "2.0.2.1" % "localcompile"
    

    See http://www.scala-sbt.org/0.13/docs/Advanced-Configurations-Example.html for examples.