Search code examples
scalasbtsbt-plugin

How to run task defined in sbt plugin


In my project I use plugin which exposes task genExport. I can run genExport task from console with:

sbt genExport

My problem is I cannot configure my sbt project to run genExport after project compilation:

lazy val sample:Project = project
  .in(file("sample"))
  .settings(
     MyPluginKeys.someKey := "someKeyValue",
     compile in Compile <<= (compile in Compile) map { x =>
       println("----------")
       // ???
       x
     }
  )
  .enablePlugins(MyPlugin)

From sbt documentation I could not get how to invoke task from plugin by name. I've experimented with:

taskKey[Unit]("genExport").taskValue

without any success. What I'm missing?


Solution

  • val genexport = TaskKey[Unit]("genExport")
    

    And

    genExport <<= genExport triggeredBy (compile in Compile)