sbt 0.11.2 how to combine ~copy-resources with ~aux-compile
Asked Answered
G

2

4

I'm using sbt 0.11.2 with xsbt-web-plugin 0.2.10 to build a Wicket (1.5.3) app. I'm using this version of Jetty:

"org.eclipse.jetty" % "jetty-webapp" % "8.0.1.v20110908" % "container",

So when I do

> container:start

my app starts up just fine.

But if I change some some of the html, the change does not kick in until I do

> copy-resources

and scala source code changes are not reflected until I do

> aux-compile
(this one was hard to find out!!)

The problem is that I want this to be reflected immediately. I can do

> ~ copy-resources

or

> ~ aux-compile    

separately so that one or the other will happen on save automatically.

The problem is that I don't see any obvious way to do both because I can't enter a 2nd tilde-prefixed command without pressing the enter key first to get the command prompt, and that cancels the running tilde command.

Thanks.


UPDATE:
I posted a minimal example of what I'm trying to do here:
https://github.com/jpswain/DummySbtScalaWicket.git

I fire this up by running sbt (0.11.2), and then doing

> container:start

So you will notice that if you do "~aux-compile" and change a log statement, or change the name that is read by the label, that will be updated on the fly. If you do "~copy-resources" and change "Hello" -> "Hola" you will see that changed on the fly. I'm trying to make it so that both will be done on save. "~container:reload /" seems to do nothing!

The answer from @Vasil Remeniuk seems like the right approach, except I haven't figure out exactly where to put the code to make it work. (I get a syntax error.) It would be great if someone would please verify if that code will work, or if I'm doing something wrong with my project that would prevent it from working?

Thanks!!
Jamie


FINAL UPDATE:
Thanks to the advice from @Vasil Remeniuk I got all this working. If anyone needs it for a quickstart to work with reloadable Jetty container, just download it at https://github.com/jpswain/DummySbtScalaWicket.git
and then from the directory run:
$ sbt

once sbt comes up, do this:

> container:start
> ~auxx
Gabby answered 12/12, 2011 at 3:4 Comment(0)
B
6

You can create your own task that calls/depends on aux-compile and copy-resources

import sbt._
import Keys._
import com.github.siasia._
import PluginKeys._

object SampleProject extends Build {

  val sampleTask = TaskKey[Unit]("combined")

  val setngs = Seq(
    sampleTask <<= (copyResources in Compile, auxCompile in Compile) map {
      (c, p) =>
    }
  )

  val root = Project("root", file(".")) settings(setngs:_*)

  override val projects = Seq(root)

}

,and call the new task continuously

~combined
Bielefeld answered 12/12, 2011 at 9:17 Comment(5)
Thanks for responding so fast! I must be doing something wrong. I get a syntax error from pasting what you wrote into my build.sbt file. I also tried making the Build.scala file and putting it in there but got an error as well. Can you verify the syntax is correct? (I'm a novice with this tool and Scala too.) I don't understand the "map ((c, a) =>)" part in particular.Gabby
1) You can create new tasks/settings only in Build.scala; 2) My code is a dummy - specifically, I'm not confident about auxCompile task key (standard SBT only has a compile task, am I right)? 3) map ((c, a) =>) evaluates tasks/settings, you pass on the left side, so you can work with their output.Bielefeld
Hi @Vasil Remeniuk! Thanks for the response! Would you mind taking a peek at the mini quickstart project I put up on github and see if you have any advice for me to make this work? I updated the question above with the link. I really appreciate it!Gabby
Checked your project @github: 1) remove build.sbt from /project 2) put the sample code above (updated) into /project/SampleBuild.scalaBielefeld
+1 accepted. Worked great! I checked it in to the example project and credited you for the solution. (github.com/jpswain/DummySbtScalaWicket/commit/…) thanks again!Gabby
S
14

~ accepts any command as an argument, including a command list:

~ ;copy-resources;aux-compile

This will run copy-resources and then aux-compile on each trigger.

I prefer Vasil's solution in this case, however, because it only requires one evaluation of the task graph.

Sikora answered 16/12, 2011 at 1:35 Comment(0)
B
6

You can create your own task that calls/depends on aux-compile and copy-resources

import sbt._
import Keys._
import com.github.siasia._
import PluginKeys._

object SampleProject extends Build {

  val sampleTask = TaskKey[Unit]("combined")

  val setngs = Seq(
    sampleTask <<= (copyResources in Compile, auxCompile in Compile) map {
      (c, p) =>
    }
  )

  val root = Project("root", file(".")) settings(setngs:_*)

  override val projects = Seq(root)

}

,and call the new task continuously

~combined
Bielefeld answered 12/12, 2011 at 9:17 Comment(5)
Thanks for responding so fast! I must be doing something wrong. I get a syntax error from pasting what you wrote into my build.sbt file. I also tried making the Build.scala file and putting it in there but got an error as well. Can you verify the syntax is correct? (I'm a novice with this tool and Scala too.) I don't understand the "map ((c, a) =>)" part in particular.Gabby
1) You can create new tasks/settings only in Build.scala; 2) My code is a dummy - specifically, I'm not confident about auxCompile task key (standard SBT only has a compile task, am I right)? 3) map ((c, a) =>) evaluates tasks/settings, you pass on the left side, so you can work with their output.Bielefeld
Hi @Vasil Remeniuk! Thanks for the response! Would you mind taking a peek at the mini quickstart project I put up on github and see if you have any advice for me to make this work? I updated the question above with the link. I really appreciate it!Gabby
Checked your project @github: 1) remove build.sbt from /project 2) put the sample code above (updated) into /project/SampleBuild.scalaBielefeld
+1 accepted. Worked great! I checked it in to the example project and credited you for the solution. (github.com/jpswain/DummySbtScalaWicket/commit/…) thanks again!Gabby

© 2022 - 2024 — McMap. All rights reserved.