1

I have a single-project build, implemented in Build.scala file with the following settings: scala lazy val root = Project( id = ProjectInfo.name, base = file("."), settings = Project.defaultSettings ++ Revolver.settings ++ Revolver.enableDebugging(port = 5050) ++ Twirl.settings ++ // more tasks omitted ++ Seq( mainClass in Compile := Some(launcherClassName), mainClass in Revolver.reStart := Some(launcherClassName), javaOptions in Revolver.reStart ++= List( "-XX:PermSize=256M", "-XX:MaxPermSize=512M", "-Dlogback.debug=false", "-Dlogback.configurationFile=src/main/resources/logback.xml" ), resolvers ++= projectResolvers, libraryDependencies ++= Dependencies.all, parallelExecution in Test := false, ) )

I would like to add sbt-web managed assets processing for the project, as I want to handle coffeescript, less and so on.

I added sbt-coffeescript plugin straight to plugins.sbt file in project folder and actually got it working. So now when I run web-assets:assets I have a coffeescript sample file in /src/main/coffeescript/foo.coffee and it gets compiled to target/web/coffeescript/main/coffeescript/foo.js.

Unfortunately, nothing gets processed when I simply run compile or run task. How do I enable processing of assets during compile in development workflow?

Andrey Neverov
  • 2,135
  • 1
  • 12
  • 21

2 Answers2

2

The issue you're having is that the old-style of specifying dependencies in projects does not work with AutoPlugins (which is what the WebPlugin is).

Specifically:

val foo = Project(
    id = "ok"
    base = file("ok")
    settings = defaultSettings // BAD!
)

i.e. if you manually place settings on the Project, you're telling sbt "I Know EVERY setting I want on this project, and I want to completely override the defaults."

The load order of sbt settings is:

  1. AutoPlugins (Core settings now come from AutoPlugins)
  2. Settings defined in Project instances
  3. Settings defined in build.sbt files in the base directory of a project.

The above code is re-applying ALL of the sbt default settings from 0.13.x series, which will overwrite anything that the AutoPlugins previously enabled. This is by design, as any other mechanism wouldn't be "correct".

If you're migrating to using AutoPlugins, simply modify your build to be:

lazy val root = Project(
  id = ProjectInfo.name,
  base = file("."))
  settings = 
    // NOTICE we dropped the defaultSettings
    Revolver.settings   
    ++ Revolver.enableDebugging(port = 5050)
    ++ Twirl.settings
    ++ // more tasks omitted
    ++ Seq(
      mainClass in Compile := Some(launcherClassName),
      mainClass in Revolver.reStart := Some(launcherClassName),
      javaOptions in Revolver.reStart ++= List(
        "-XX:PermSize=256M",
        "-XX:MaxPermSize=512M",
        "-Dlogback.debug=false",
        "-Dlogback.configurationFile=src/main/resources/logback.xml"
      ),
      resolvers ++= projectResolvers,
      libraryDependencies ++= Dependencies.all,
      parallelExecution in Test := false,
   )
)
jsuereth
  • 5,604
  • 40
  • 40
  • Josh, thanks for the answer! Unfortunately, this didn't help – still changes in files under /src/main/assets don't get compiled (but compile command itself notices them and recompiles all the other stuff). Maybe you could take a look at the whole build file and point what am I doing wrong? plugins.sbt: https://gist.github.com/neverov/46e1c2d113efad18bdf6, build.scala: https://gist.github.com/neverov/ecc475df180c2fa907ea – Andrey Neverov Sep 12 '14 at 08:40
  • Oh, and I forgot to mention, sbt version is 0.13.5. – Andrey Neverov Sep 12 '14 at 10:43
1

To run assets generation on compilation I did this:

settings = ... ++ Seq(
  pipelineStages := Seq(rjs),
  (compile in Compile) <<= compile in Compile dependsOn (stage in Assets),
  // ...
)

Than when I run compile, stage command is also executed, thus running sbt-web's pipeline. The question for me is how to make generated assets to become available as part of managed resources (I'm trying to get sbt-web working with xsbt-web-plugin and liftweb)

Oleg Stepura
  • 95
  • 2
  • 11
  • Were you successful in getting sbt-web and xsbt-web-plugin working together? I've been struggling with that for the last day or so and just asked a question that you might be able to answer: http://stackoverflow.com/questions/29154360/how-can-sbt-web-output-be-used-with-xsbt-web-plugin-via-a-sbt-project-dependency – Martin Snyder Mar 19 '15 at 20:32
  • Finally I decided that `sbt-web` is monster I don't want to use. For asset management there are far way more convinient and faster (!) tools. Developing with `webpack` was a pleasure. But I didn't get to production use of `webpack` yet. – Oleg Stepura Dec 11 '15 at 09:52