sbtspraysbt-web

Minimal sbt-web pipeline without Play


I'm using spray to create a single page app, and cannot get sbt-web to process any of my inputs. I started with WebJars, because, https://github.com/sbt/sbt-web/blob/master/README.md says:

One last thing regarding the public and public-test folders... any WebJar depended on by the project will be automatically extracted into these folders e.g. target/web/public/lib/jquery/jquery.js.

However, I see no such "web" folder in the target folder. I thought maybe WebJars was too complicated of an example to start with, so I instead added a jquery.js file to the root of the asset folder, and set up sbt-uglify to do some processing on it. Yet, still, I see no evidence that SbtWeb is working. I've run sbt --debug clean run and grepped the output for any output from SbtWeb or Uglify, but no errors or warnings and can't find anything wrt SbtWeb or Uglify. Just acknowledgement that it seems to "deduce" the plugins:

[debug] deducing auto plugins based on known facts [debug]   :: sorting:: found: 
...
[debug]   :: sorted deduced result: List(sbt.plugins.CorePlugin, com.typesafe.sbt.web.SbtWeb, com.typesafe.sbt.jse.SbtJsEngine, net.ground5hark.sbt.concat.SbtConcat, sbt.plugins.IvyPlugin, com.typesafe.sbt.jse.SbtJsTask, sbt.plugins.JvmPlugin, com.typesafe.sbt.uglify.SbtUglify, sbt.plugins.JUnitXmlReportPlugin)

Here is my directory structure:

./build.sbt
./project/plugins.sbt
./src/main/assets/js/jquery.js
./src/main/resources/html/uikit/login.html
./src/main/scala/Boot.scala
./src/main/scala/main.scala

Here is my project/plugins.sbt:

resolvers += Resolver.sonatypeRepo("releases")

addSbtPlugin("com.typesafe.sbt" % "sbt-web" % "1.0.2")
addSbtPlugin("net.ground5hark.sbt" % "sbt-concat" % "0.1.8")
addSbtPlugin("com.typesafe.sbt" % "sbt-uglify" % "1.0.3")

Here is my ./build.sbt:

organization  := "com.test123.spray"

version       := "0.1"

scalaVersion  := "2.11.6"

scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "utf8")

libraryDependencies ++= {
  val akkaV = "2.3.9"
  val sprayV = "1.3.3"
  Seq(
    "io.spray"            %%  "spray-can"     % sprayV,
    "io.spray"            %%  "spray-routing" % sprayV,
    "io.spray"            %%  "spray-testkit" % sprayV  % "test",
    "com.typesafe.akka"   %%  "akka-actor"    % akkaV,
    "com.typesafe.akka"   %%  "akka-testkit"  % akkaV   % "test",

    // client side dependencies
    "org.webjars" % "jquery" % "2.1.4",
    "org.webjars" % "uikit" % "2.24.2"

  )
}

lazy val root = (project.in(file("."))).enablePlugins(SbtWeb)

pipelineStages := Seq(uglify)

includeFilter in uglify := GlobFilter("js/*.js")

Here is what the root of my ./target folder looks like:

resolution-cache/
scala-2.11/
streams/

No ./target/web folder. Any ideas why?

References:


Solution

  • That'll learn me. I was using an old version of sbt-web. When I update it to the latest, it works as expected.

    The lesson is not to copy/paste snippets like this:

    addSbtPlugin("com.typesafe.sbt" % "sbt-web" % "1.0.2")

    from the web. But, rather to find the latest version, manually, by one of the following methods:

    1. If the GitHub (et al) page has a "Build Passing" badge, click on it to navigate to the build server where the latest versions are listed.
    2. Look at the branches in GitHub
    3. See if you can navigate to the repository for the dependency, such as Maven Central, and browse there. I didn't have luck with this one. The problem I had is that I knew it wasn't on Maven, and didn't know where else to look.
    4. Plug in some bogus version in SBT, and look at the output for where SBT tried to look and failed:

      [warn]  module not found: com.typesafe.sbt#sbt-web;3.1.2
      [warn] ==== typesafe-ivy-releases: tried
      [warn]   http://repo.typesafe.com/typesafe/ivy-releases/com.typesafe.sbt/sbt-web/scala_2.10/sbt_0.13/3.1.2/ivys/ivy.xml
      [warn] ==== sbt-plugin-releases: tried
      [warn]   http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.typesafe.sbt/sbt-web/scala_2.10/sbt_0.13/3.1.2/ivys/ivy.xml
      

    I'm positive there are better ways to find the latest versions of things that I'm just unaware of. For those more experienced than me please comment with a better way.