Sbt 0.11 perform the required tasks

My projects still use sbt 0.7.7, and it’s very convenient for me to have utility classes that I can run from the sbt prompt. I can also combine this with properties that are separately supported β€” typically for environment-related values ​​that change from hosts to hosts. This is an example of my project definition in the project/build directory:

 class MyProject(info: ProjectInfo) extends DefaultProject(info) { //... lazy val extraProps = new BasicEnvironment { // use the project Logger for any properties-related logging def log = MyProject.this.log def envBackingPath = path("paths.properties") // define some properties that will go in paths.properties lazy val inputFile = property[String] } lazy val myTask = task { args => runTask(Some("foo.bar.MyTask"), runClasspath, extraProps.inputFile.value :: args.toList).dependsOn(compile) describedAs "my-task [options]" } } 

Then I can use my task as my-task option1 option2 under the sbt shell.

I read the new sbt 0.11 documentation at https://github.com/harrah/xsbt/wiki , including the Tasks and TaskInputs sections , and to be honest, I'm still struggling with how to achieve what I did on 0.7.7 .

It seems that additional properties can simply be replaced by a separate environment.sbt , that tasks should be defined in project/build.scala before being set in build.sbt . It also looks like there is support for completion that looks very interesting.

In addition, I am somewhat overloaded. How to accomplish what I did with the new sbt?

+8
scala sbt
source share
1 answer

You can define a task as follows:

 val myTask = InputKey[Unit]("my-task") 

And your setup:

 val inputFile = SettingKey[String]("input-file", "input file description") 

You can also define a new configuration, for example:

 lazy val ExtraProps = config("extra-props") extend(Compile) 

add this configuration to your project and use it to set parameters for this configuration:

 lazy val root = Project("root", file(".")).config( ExtraProps ).settings( inputFile in ExtraProps := ... ... myTask in ExtraPops <<= inputTask { (argTask:TaskKey[Seq[String]]) => (argTask, inputFile) map { (args:Seq[String], iFile[String]) => ... } } ).dependsOn(compile) 

then run your task with the additional details: my-task

+3
source share

All Articles