如何在sbt-release步骤中更改子项目设置

时间:2019-06-26 14:23:14

标签: scala sbt

我将sbt-release插件用于几个项目。我使用的一个步骤是docker:publish的{​​{1}}将映像推送到Docker集线器。

sbt-native-packager依靠sbt-native-packager设置来决定是否更新dockerUpdateLatest标签。默认值为latest,如果为false,它将更新true

对于一个在根目录下没有子项目的项目,我可以使用自定义latest来更改该设置,具体取决于我是否发布ReleaseStep,即我不想如果版本以SNAPSHOT结尾,请更新latest标签。

SNAPSHOT

以上内容适用于该项目。

对于另一个项目,根目录下聚合了多个项目。我想做类似的事情

lazy val setDockerReleaseSettings = ReleaseStep(action = oldState => {
  // dockerUpdateLatest is set to true if the version is not a SNAPSHOT
  val extracted = Project.extract(oldState)
  val v = extracted.get(Keys.version)
  val snap = v.endsWith("SNAPSHOT")
  if (!snap) extracted
      .appendWithSession(Seq(dockerUpdateLatest := true), oldState)
  else oldState
})

但是它似乎不起作用。我也尝试了lazy val setDockerReleaseSettings = ReleaseStep(action = oldState => { // dockerUpdateLatest is set to true if the version is not a SNAPSHOT val extracted = Project.extract(oldState) val v = extracted.get(Keys.version) val snap = v.endsWith("SNAPSHOT") if (!snap) extracted .appendWithSession(Seq(dockerUpdateLatest in api := true, dockerUpdateLatest in portal := true), oldState) else oldState }) dockerUpdateLatest in Global无济于事。有任何想法如何在这些子项目中更改dockerUpdateLatest in root

1 个答案:

答案 0 :(得分:0)

可以用set every dockerUpdateLatest := true解决。我这样做了一个自定义的ReleaseStep

lazy val createSetDockerUpdateLatestCommand = ReleaseStep(action = state => {
  // dockerUpdateLatest is set to true if the version is not a SNAPSHOT
  val snap = Project.extract(state).get(Keys.version).endsWith("SNAPSHOT")

  val setDockerUpdateLatest = if (!snap)
    Command.command("setDockerUpdateLatest") {
      "set every dockerUpdateLatest := true" ::
      _
    }
  else
    Command.command("setDockerUpdateLatest") {
      "" ::
      _
    }

  state.copy(definedCommands = state.definedCommands :+ setDockerUpdateLatest)
})

然后我运行setDockerUpdateLatest