Skip to content

Instantly share code, notes, and snippets.

@fedesilva
Created March 12, 2012 22:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fedesilva/2025004 to your computer and use it in GitHub Desktop.
Save fedesilva/2025004 to your computer and use it in GitHub Desktop.
sbt 0.11.2 task dependencies [PARTIALLY SOLVED]
import sbt._
import Keys._
/**
* How in the world do I make bye depend on hello?
* And how do I depend on a task like test?
* I have not been able to make this work
goodbyeTask <<= goodbyeTask.dependsOn(helloTask) as in https://github.com/harrah/xsbt/wiki/Tasks
no matter where I stick it!
Halp!
*/
object Build extends Build {
lazy val project = Project (
"virtualusers",
file (".")
)
override lazy val settings = super.settings ++ Seq(
helloTask,
goodbyeTask
)
val hello = TaskKey[Unit]("hello", "Prints 'Hello World'")
val helloTask = hello := { println( "Hello World") }
val goodbye = TaskKey[Unit]("bye", "Prints 'Good Bye, cruel world'")
val goodbyeTask = goodbye := { println("Good Bye, cruel world") }
}
import sbt._
import Keys._
/**
* So I tried this https://groups.google.com/forum/?fromgroups#!topic/simple-build-tool/v7y64K15PRU
* and I get what you see in the next file
*/
object Build extends Build {
lazy val project = Project (
"virtualusers",
file (".")
)
override lazy val settings = super.settings ++ Seq(
helloTask,
goodbyeTask <<= goodbyeTask dependsOn (helloTask)
)
val hello = TaskKey[Unit]("hello", "Prints 'Hello World'")
val helloTask = hello := { println( "Hello World") }
val goodbye = TaskKey[Unit]("bye", "Prints 'Good Bye, cruel world'")
val goodbyeTask = goodbye := { println("Good Bye, cruel world") }
}
import sbt._
import Keys._
/**
* I have made progress ... now I need to hook into the "standard" tasks like compile.
*/
object Build extends Build {
lazy val project = Project (
"sbt-task-dependencies",
file (".")
)
override lazy val settings = super.settings ++ Seq(
helloTask,
goodbyeTask
)
val hello = TaskKey[Unit]("hello", "Prints 'Hello World'")
val helloTask = hello := { println( "Hello World") }
val goodbye = TaskKey[Unit]("bye", "Prints 'Good Bye, cruel world'")
val goodbyeTask = goodbye <<= (hello) map { h => println("goodbye") }
}
I admit I am clueless. I've also looked at the wiki (obviously as my example is clearly ripped of there) but I can not find a full blown build.scala example.
What I want to achieve is just move some files around and then compress them with the `assembly`ed jar for distribution (bundle). That part is fine, I have a task that does that but I can't say:
when I type bundle I want to the tests to be run and then an assembly created.
Halp! :'(
[info] Compiling 1 Scala source to /Users/fede/Workshop/code/exploratory/sbt/taskDependencies/project/target/scala-2.9.1/sbt-0.11.2/classes...
[error] /Users/fede/Workshop/code/exploratory/sbt/taskDependencies/project/Build.scala:18: reassignment to val
[error] goodbyeTask <<= goodbyeTask dependsOn (helloTask)
[error] ^
[error] one error found
@retronym
Copy link

build2.scala:15 
-      helloTask
+      helloTask,

@fedesilva
Copy link
Author

@retronym, thanks.

It was metastasis (cut'n'paste) error both in the version of the code and it's output; It was late and I just did not recheck.
The gist is updated and the output is the correct too.

@fedesilva
Copy link
Author

for some reason, the gist files are not in the order I create them. Anyway, this is mostly history now :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment