How to change setting inside SBT command?

丶灬走出姿态 提交于 2019-11-27 01:07:40
Rogach

With the help from sbt mailing list, I was able to create a solution as follows:

def publishSnapshot = Command.command("publish-snapshot") { state =>
  val extracted = Project extract state
  import extracted._
  val eVersion = getOpt(version).get // getting current version
  runTask(publish in Compile,
    append(Seq(version := "newVersion"), state),
    true
  )
  state
}

This actually did not work for me. I'm using SBT 0.13.7

Adapting what I had to do to the above example, I had to do something like:

def publishSnapshot = Command.command("publish-snapshot") { state =>
  val extracted = Project extract state
  val newState = extracted.append(Seq(version := "newVersion"), state)
  val (s, _) = Project.extract(newState).runTask(publish in Compile, newState)
  s
}

Or alternatively do:

def publishSnapshot = Command.command("publish-snapshot") { state =>
  val newState =
    Command.process("""set version := "newVersion" """, state)
  val (s, _) = Project.extract(newState).runTask(publish in Compile, newState)
  s
}

To update an arbitrary setting from a command, do something like the following:

def updateFoo = Command.command("updateFoo") { state =>
 val extracted = Project extract state
 import extracted._
 println("'foo' set to true")
 //append returns state with updated Foo
 append(Seq(foo := true), state)
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!