danbroooks danbroooks - 1 month ago 19
Scala Question

Unable to make reference to object in build.sbt, "error: not found: value hooks"

I'm trying to add gulp to my Play application, I have created a

PlayRunHook
object that should allow me to trigger the
gulp
command, but when I do
sbt run
I'm getting an error saying it could not find the object. Here is my hook:

package hooks

object Gulp extends CommandHook {

override def beforeStarted(): Unit = {
exec("gulp")
}
}


And then in
build.sbt
:

lazy val root = (project in file(".")).enablePlugins(PlayScala)

scalaVersion := "2.11.7"

scalacOptions ++= Seq("-deprecation")

libraryDependencies ++= Seq(
"junit" % "junit" % "4.10" % "test",
"org.reactivemongo" %% "play2-reactivemongo" % "0.11.14",
"com.typesafe.play" %% "play" % "2.5.0",
"com.typesafe.play" %% "play-netty-server" % "2.5.0"
)

PlayKeys.playRunHooks += hooks.Gulp()


But I get:

build.sbt:18: error: not found: value hooks
PlayKeys.playRunHooks += hooks.Gulp()

Answer

You have to create Gulp object in project/ directory like below:

import play.sbt.PlayRunHook
import sbt._

object Gulp {
  def apply(base: File): PlayRunHook = {

    object GulpProcess extends PlayRunHook {

      override def beforeStarted(): Unit = {
        Process("gulp", base).run
      }
    }

    GulpProcess
  }
}

Then in your build.sbt:

PlayKeys.playRunHooks += Gulp(baseDirectory.value)

For more details check this guide.

Comments