Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
環境依存ファイルを変更するためのsbtのカスタムタスク
import sbt._
import sbt.Keys._
import sbt.IO._
object ProjectBuild extends Build {
val dependencyFiles = Seq("src/main/webapp/WEB-INF/web.xml")
val enviroment = InputKey[Unit]("enviroment", "chagen enviroment seting.")
val enviromentTask = enviroment <<= inputTask { (argTask: TaskKey[Seq[String]]) =>
argTask map { (args: Seq[String]) =>
changeEnviroment(args.first)
}
}
def changeEnviroment(env:String) = {
println("change enviroment:" + env)
dependencyFiles.foreach { path =>
val envPath = path + "." + env
val envFile = new File(envPath)
val msg = if (envFile.exists) {
copyFile(envFile, new File(path))
"copy:" + envPath
} else {
"not found:" + envPath
}
println(msg)
}
}
lazy val root = Project( id = "", base = file("."),
settings = Defaults.defaultSettings ++ Seq(enviromentTask)).dependsOn()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.