Re: [sbt] How to make a sbt task use a specific configuration scope?

246 views
Skip to first unread message

Mark Harrah

unread,
Aug 8, 2012, 8:40:09 AM8/8/12
to simple-b...@googlegroups.com
Hi Raphael,

On Wed, 8 Aug 2012 00:20:23 -0700 (PDT)
esarbe <raphael....@gmail.com> wrote:

> Hello there,
>
> I have a task lazy val task = TaskKey[Unit] that takes a lazy val setting =
> SettingKey[String] as input. I also have three different, independent
> config scopes (config("dev"), config("stage"), config("prod")) and a
> build.sbt file that specifies different values for setting for each of the
> config scopes (setting in stage := "foo", ... ).
>
> I expected that calling task using the config scope prefix would make the
> task use the values from the respective config scope (e.g. >dev:task would
> make the task use the setting values from the dev scope using command
> >stage:task would make the task use the setting values from stage scope,
> ...). However, this does not seem to work.
>
> How can I force task to use the settings from a specific config scope?
> (Preferably at runtime/from CLI and not by creating multiple task that each
> refer to a pre-scoped setting.)

Creating them at runtime is an interesting idea, but it is not supported. However, it is not much work to put a task in multiple scopes.

def mkTask(c: Configuration) =
task in c <<= setting in c map { ... }

val configs = Seq(dev, stage, prod)
val allConfigs: Seq[Setting[_]] = configs map mkTask

> build.sbt: http://pastie.org/4405396
> Build.scala: http://pastie.org/4405421

and allConfigs replaces Seq(taskTask) in your Build.Scala.

-Mark

> I'm grateful for any help or hint you can offer.
>
> Thanks in advance,
> Raphael Bosshard (esarbe)
>
> --
> 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/-/gXDe-2kn0zcJ.
> 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.
>

Reply all
Reply to author
Forward
0 new messages