How do I run Scala code in SBT Build.scala just before compiling Scala files?

I'm trying to run some Scala code, just print "Hello" for now, but I want to run the Scala code just before compiling the Scala code in an SBT project. I found that the following works in build.sbt.

compile in Compile <<= compile in Compile map {
  comp => {
    println("Hello")
  }
  comp
}

      

However I want to do it in Build.scala, how do I do it in Build.scala?

+3


source to share


1 answer


While you import the usual:

import sbt._
import Keys._

      

you should be able to use exactly the same code in Build.scala

.



That being said, you should use dependsOn

instead map

:

compile in Compile <<= (compile in Compile).dependsOn(Def.task {
  println("Hello")
})

      

+3


source







All Articles