0

I am using "sbt-releases" and need to execute "release" from inside a task, but the problem is that "release" is a command not task.

so is it possible to execute a command from inside a task in sbt ?

Why I need to execute a release from inside a task ?

I want to create a task to execute a release if some condition satisfied, else trigger a normal build. I tried to achieve that by through changing the releaseProcess in sbt but the problem is that it is a SettingKey not a taskKey, and tasks can't be used inside settings because settings gets initialized once in the project loading.

Mohamed Kamaly
  • 127
  • 3
  • 10
  • 1
    "I want to create a task": make it a command instead, problem solved. Or is there some reason it must be a task? – Seth Tisue Jan 01 '16 at 20:18
  • I created a command eventually, I was avoiding it because I thought commands had to be in "build.scala" since all the examples used this way and I was avoiding scattering the build configuration between "build.sbt" and "build.scala", but it turns out it can be written inside "built.sbt" normally – Mohamed Kamaly Jan 02 '16 at 07:48

1 Answers1

1

I created a command eventually. Thanks @Seth Tisue

lazy val myproject = (project in file("myproject").
settings(
  commands += Command.command("releaseIfRequired") { state =>
    val (stateAfterTask, condition) = Project.extract(state).runTask(conditionTask, state)

    if (condition) {
      Parser.parse(" with-defaults", ReleaseKeys.releaseCommand.parser(stateAfterTask)) match {
        case Right(cmd) => cmd()
        case Left(msg) => throw sys.error(s"Error triggering release command:\n$msg")
      }
    }
    else {
      Project.extract(stateAfterTask).runTask(build, stateAfterTask)._1
    }
  }
)
Mohamed Kamaly
  • 127
  • 3
  • 10