How to change a version setting inside a single command?

52 views
Skip to first unread message

Rogach

unread,
Jan 10, 2013, 10:11:38 AM1/10/13
to simple-b...@googlegroups.com
In short, I want to have a command ("publish-snapshot"), which would run a "publish" task with modified "version" setting (that setting is to be computed at the time of execution of the command).
I figured out how to get current value of the version inside command, and Project.runTask(<task>, <scope>, ...) seems to be a right call for invoking that publish task.

The only thing that I'm confused with is how to modify the State instance with a new version value. All my attempts seem to do nothing to the original version setting. I posted my latest attempt - http://pastebin.com/DAGfMQEa .
Is there some way to fix that behavior?

Jason Zaugg

unread,
Jan 10, 2013, 12:38:34 PM1/10/13
to simple-b...@googlegroups.com
Take a look at the sources of the sbt-release plugin [1] which does just this.

-jason

Kevin Scaldeferri

unread,
Jan 10, 2013, 1:14:38 PM1/10/13
to simple-b...@googlegroups.com
We do something like this (some details elided):

  override lazy val projectSettings = 
     ...
      Seq(commands += stampVersion) ++
      addCommandAlias("publish-integration", ";stamp-version ;publish")

  def stampVersion = Command.command("stamp-version") { state =>
    val extracted = Project.extract(state)
    extracted.append(List(version in ThisBuild ~= { ver =>
      val stmp = stamp(ver)
      Logging.info("Stamping version %s".format(stmp))
      stmp
    }), state)
  }

  def stamp(version: String): String = {
    // whatever you want
  }





--
You received this message because you are subscribed to the Google Groups "simple-build-tool" group.
To view this discussion on the web visit https://groups.google.com/d/msg/simple-build-tool/-/SBNIbfIFDRgJ.
To post to this group, send email to simple-b...@googlegroups.com.
To unsubscribe from this group, send email to simple-build-t...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/simple-build-tool?hl=en.

Rogach

unread,
Jan 11, 2013, 3:59:27 AM1/11/13
to simple-b...@googlegroups.com
Thanks a lot! Now it works flawlessly.
Reply all
Reply to author
Forward
0 new messages