Reputation: 309
I am writing a small sbt plugin to generate some files which should be configurable by a target path parameter. Therefore I wrote this plugin code:
object GeneratorPlugin extends AutoPlugin {
object autoImport {
val targetPath = settingKey[String]["target directory"]
val generateFiles = taskKey[Unit]["generate files"]
}
import autoImport._
override def trigger = allRequirements
override lazy val buildSettings = Seq(
targetPath := ".",
generateFiles := generateTask
)
lazy val generateTask = Def.task {
System.out.println(targetPath.value)
}
}
When importing this using addSbtPlugin
in project/plugins.sbt
and running it with sbt generateFiles
is correctly printing .
. However when I change the value of targetPath
in my build.sbt
the result does not change.
targetPath := "/my/new/path"
Result of sbt generateFiles
is still .
.
Is there a way to change the value of targetPath
within my build.sbt
when importing the plugin?
Upvotes: 0
Views: 272
Reputation: 6102
You can change it like so:
targetPath in ThisBuild := "/my/new/path"
or in the sbt 1.1's new slash syntax
ThisBuild / targetPath := "/my/new/path"
Upvotes: 1