I'd like to propose an approach with custom configuration.
The following is a build.sbt
of a sample project:
lazy val CustomPackage = config("custompackage") extend(Compile) describedAs("Custom package configuration")
packageBin in CustomPackage := {
val log = streams.value.log
import log._
info("""Returning custom packaging artifact, i.e. file(".")""")
file(".")
}
lazy val root = project in file(".") overrideConfigs (CustomPackage)
In the above build configuration, there's custompackage
configuration that scopes settings and tasks. As an example of how it can change the behaviour of packageBin
task there's a (re)definition in this scope. The last line adds the custom configuration to the project.
When you run SBT shell (sbt
), you will notice that the real packageBin
task is untouched while it changes in custompackage
scope. By default, you're in Compile
configuration. To change it, you need to use the extended syntax to execute a task in another configuration.
[root]> configuration
[info] compile
[root]> show packageBin
[info] /Users/jacek/sandbox/so/config-package/target/scala-2.10/root_2.10-0.1-SNAPSHOT.jar
[success] Total time: 0 s, completed Feb 8, 2014 2:27:10 PM
When you change configuration axis to custompackage
the task packageBin
changes.
[root]> custompackage:configuration
[info] custompackage
[root]> show custompackage:packageBin
[info] Returning custom packaging artifact, i.e. file(".")
[info] .
[success] Total time: 0 s, completed Feb 8, 2014 2:27:20 PM
[root]> custompackage:packageBin
[info] Returning custom packaging artifact, i.e. file(".")
[success] Total time: 0 s, completed Feb 8, 2014 2:27:25 PM
All tested under SBT 0.13.1.
[root]> about
[info] This is sbt 0.13.1
[info] The current project is {file:/Users/jacek/sandbox/so/config-package/}root 0.1-SNAPSHOT
[info] The current project is built against Scala 2.10.3
[info] Available Plugins: com.typesafe.sbt.SbtGit, com.typesafe.sbt.SbtProguard, growl.GrowlingTests, org.sbtidea.SbtIdeaPlugin, np.Plugin, com.timushev.sbt.updates.UpdatesPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.3