scalaplayframeworksbtsbt-web

How to enable SbtWeb in not-play project?


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?


Solution

  • 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,
       )
    )