Re: [sbt] How to use settings from build.sbt file in task.

244 views
Skip to first unread message

Josh Suereth

unread,
Jul 19, 2012, 2:14:26 PM7/19/12
to simple-b...@googlegroups.com
To answer your question, just redefine the TaskKey in Build.scala.   As long as the types line up, everything is gravy.

I'd recommend, however, to always define TaskKey's in Build.scala or a .scala file if you use them.  Then, import it into build.sbt.

- Josh

On Thu, Jul 19, 2012 at 10:03 AM, Dawid Melewski <dawid.m...@gmail.com> wrote:
Hi,

How can i use settings from build.sbt file in Build.scala tasks?

i.e. i have task:

{code}

val hello = TaskKey[Unit]("hello", "Prints 'Hello World'")

val helloTask = hello := {
 ...
 IO.zip(files, name+"-"+version+".zip")
}

{code}
but with code above i have file with "sbt.SettingKey$$anon$4...@1484034-sbt.SettingKey$$anon$4@2e6f1694"

is possible to get value from SettingKey?

thanks for any help

dm

--
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/-/wn59LunzOY0J.
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.

Jesse C

unread,
Jul 19, 2012, 2:37:05 PM7/19/12
to simple-b...@googlegroups.com
Don't think that is what he is trying to do.  Looks like he wants to use the built in keys 'name' and 'version' in
another task.

wouldn't the correct way to do that be

val helloTask = hello <<= (name, version) map  { (n, v) =>
   IO.zip(files, n + "-" + v + ".zip")

Josh Suereth

unread,
Jul 19, 2012, 2:50:41 PM7/19/12
to simple-b...@googlegroups.com
Ahhh, so in Build.scala I'd have the following:

object MyBuild extends Build {
  val hello = TaskKey[Unit](...)

  // THis can be easily tested in console-project
  def helloTaskImpl(name: String, version: String) = ...

  def helloTask = hello <<=  (name, version) map helloTaskImpl


  val projectX = Project(...) settings(helloTask)
}


I like that three way split (well, at least the `helloTaskImpl`) because it's far easier to test a "vanilla" function.

Dawid Melewski

unread,
Jul 20, 2012, 5:22:35 AM7/20/12
to simple-b...@googlegroups.com
Thanks :)

this is exactly what i need

greets

}


- Josh

but with code above i have file with "sbt.SettingKey$$anon$4@1484034-sbt.SettingKey$$anon$4@2e6f1694"


is possible to get value from SettingKey?

thanks for any help


dm

--
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/-/wn59LunzOY0J.
To post to this group, send email to simple-build-tool@googlegroups.com.
To unsubscribe from this group, send email to simple-build-tool+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/simple-build-tool?hl=en.

--
You received this message because you are subscribed to the Google Groups "simple-build-tool" group.
To post to this group, send email to simple-build-tool@googlegroups.com.
To unsubscribe from this group, send email to simple-build-tool+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/simple-build-tool?hl=en.

--
You received this message because you are subscribed to the Google Groups "simple-build-tool" group.
To post to this group, send email to simple-build-tool@googlegroups.com.
To unsubscribe from this group, send email to simple-build-tool+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages