SBT run code in project after compile

sbt

Solution

You can use the triggeredBy method like this:

yourTask <<= (fullClasspath in Runtime) map {classpath =>
  val loader: ClassLoader = ClasspathUtilities.toLoader(classpath.map(_.data).map(_.getAbsoluteFile))
  loader.loadClass("your.class.Here").newInstance()
} triggeredBy(compile in Compile)

This will instantiate your class that has just been compiled, using the runtime classpath for your application, after any compile.

Problem

we need to run some code after the compile step. Making things happen after the compile step seems easy: ``` compile in Compile <<= (compile in Compile) map{x=> // post-compile work doFoo() x } ``` but how do you run something in the freshly compiled code? More info on the scenario: we are using less for css in a lift project. We wanted lift to compile less into css on the fly (if needed) to help dev, but produce less using the same code, during the build, before tests etc run. less-sbt may help but we are interested in how to solve this generally.

Original source

Related problems