Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sbt-web asset output directory setup question #122

Open
Athelionas opened this issue Aug 28, 2015 · 1 comment
Open

sbt-web asset output directory setup question #122

Athelionas opened this issue Aug 28, 2015 · 1 comment

Comments

@Athelionas
Copy link

Scenario

I have a fairly simple Scalatra project with Scala.js and LESS for which I need to create an sbt build configuration. The project is separated into three parts: jvm, js, shared code.

My current build config uses xsbt-web-plugin for WAR packaging and I'd like to set up sbt-web so it could deal with the processing of LESS sources.

The Issue

With current config, when I run package command, sbt-web puts the assets in WEB-INF/classes/main/META-INF/resources/webjars/dataretrieverjvm/0.1.0-SNAPSHOT. I'd like to place them in WEB_INF/public instead, but I can't figure out how I could achieve that.

This is how my Build.scala looks like at the moment:

import org.scalajs.sbtplugin.cross.CrossProject
import sbt._
import com.earldouglas.xwp._
import play.twirl.sbt._
import org.scalajs.sbtplugin.ScalaJSPlugin
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
import com.typesafe.sbt.web._
import com.typesafe.sbt.web.SbtWeb.autoImport._
import com.typesafe.sbt.less.SbtLess.autoImport._

object DataRetrieverBuild extends Build {
  private val organization       = "Foobar Ltd"
  private val scalaVersion       = "2.11.7"
  private val scalaBinaryVersion = "2.11"
  private val scalatraVersion    = "2.3.1"
  private val akkaVersion        = "latest.release"
  private val scalacOptions      = Seq(
    "-unchecked", "-deprecation", "-Yinline-warnings", "-optimise", "-target:jvm-1.8", "-Xlint", "-feature"
  )
  private val javacOptions       = Seq(
    "-Xlint:all"
  )
  private val jvmLibraryDependencies    = Def.setting(
    Seq(
      "ch.qos.logback" % "logback-classic" % "latest.release",
      "com.mchange" % "c3p0" % "latest.release",
      "com.typesafe.akka" %% "akka-actor" % akkaVersion,
      "com.typesafe.play" %% "anorm" % "latest.release",
      "javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided",
      "org.apache.commons" % "commons-email" % "latest.release",
      "org.json4s" %% "json4s-jackson" % "latest.release",
      "org.scalatra" %% "scalatra" % scalatraVersion,
      "org.scalatra" %% "scalatra-auth" % scalatraVersion,
      "org.slf4j" % "slf4j-api" % "latest.release",
      "com.ibm.tools.target" % "was-liberty" % "8.5.x.3" % "provided"
    )
  )
  private val jsLibraryDependencies     = Def.setting(
    Seq(
      "be.doeraene" %%% "scalajs-jquery" % "latest.release",
      "org.scala-js" %%% "scalajs-dom" % "latest.release",
      "org.webjars" % "bootstrap" % "3.3.5" exclude("org.webjars", "jquery")
    )
  )
  private val jsWebjarDependencies      = Def.setting(
    Seq(
      "org.webjars" % "jquery" % "2.1.4" / "jquery.js" minified "jquery.min.js",
      "org.webjars" % "underscorejs" % "1.8.3" / "underscore.js" minified "underscore-min.js",
      "org.webjars" % "bootstrap" % "3.3.5" / "bootstrap.js"  minified "bootstrap.min.js" dependsOn("jquery.js", "underscore.js", "moment.js"),
      "org.webjars" % "ractive" % "0.7.1" / "ractive.js" minified "ractive.min.js",
      "org.webjars" % "momentjs" % "2.10.6" / "moment.js" minified "moment.min.js"
    )
  )
  private[this] val artifactPath = file(".")
  private val autoAPIMappings    = true
  private val scalaDocOptions    = Seq(
    "-implicits", "-diagrams"
  )

  private lazy val sharedBuildSettings = Seq(
    Keys.organization                                  :=  organization,
    Keys.name                                          :=  "DataRetrieverShared",
    Keys.version                                       :=  "0.1.0-SNAPSHOT",
    Keys.scalaVersion                                  :=  scalaVersion,
    Keys.scalaBinaryVersion                            :=  scalaBinaryVersion,
    Keys.scalacOptions                                 ++= scalacOptions,
    Keys.scalacOptions in (Compile, Keys.doc)          ++= scalaDocOptions ++ Opts.doc.title("DataRetrieverShared"),
    Keys.javacOptions                                  ++= javacOptions,
    Keys.target in (Compile, Keys.doc)                 :=  file("jvm-api"),
    Keys.autoAPIMappings                               :=  autoAPIMappings
  )

  private lazy val jvmBuildSettings = Seq(
    Keys.organization                                  :=  organization,
    Keys.name                                          :=  "DataRetrieverJVM",
    Keys.version                                       :=  "0.1.0-SNAPSHOT",
    Keys.scalaVersion                                  :=  scalaVersion,
    Keys.scalaBinaryVersion                            :=  scalaBinaryVersion,
    Keys.scalacOptions                                 ++= scalacOptions,
    Keys.scalacOptions in (Compile, Keys.doc)          ++= scalaDocOptions ++ Opts.doc.title("DataRetrieverJVM"),
    Keys.javacOptions                                  ++= javacOptions,
    Keys.checksums in Keys.update                      :=  Nil,
    Keys.resolvers                                     ++= Seq(
      "IBM" at "http://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/maven/repository/"
    ),
    Keys.libraryDependencies                           ++= jvmLibraryDependencies.value,
    Keys.artifactPath in Keys.`package`                ~=  { defaultPath => artifactPath / defaultPath.getName },
    Keys.artifactName in Keys.`package`                :=  {
      (sv: ScalaVersion, module: ModuleID, artifact: Artifact) =>
        s"${artifact.name}.${artifact.extension}"
    },
    WebappPlugin.autoImport.webappWebInfClasses        := true,
    LessKeys.compress in Assets                        :=  true,
    WebKeys.webTarget                                  :=  Keys.target.value / "webapp" / "WEB-INF",
    Keys.target in (Compile, Keys.doc)                 :=  file("jvm-api"),
    Keys.autoAPIMappings                               :=  autoAPIMappings
  )

  private lazy val jsBuildSettings = Seq(
    Keys.organization                                  :=  organization,
    Keys.name                                          :=  "DataRetrieverJS",
    Keys.version                                       :=  "0.1.0-SNAPSHOT",
    Keys.scalaVersion                                  :=  scalaVersion,
    Keys.scalaBinaryVersion                            :=  scalaBinaryVersion,
    Keys.scalacOptions                                 ++= scalacOptions,
    Keys.scalacOptions in (Compile, Keys.doc)          ++= scalaDocOptions ++ Opts.doc.title("DataRetrieverJS"),
    Keys.libraryDependencies                           ++= jsLibraryDependencies.value,
    jsDependencies                                     ++= jsWebjarDependencies.value,
    Keys.skip in packageJSDependencies                 :=  false,
    Keys.target in (Compile, Keys.doc)                 :=  file("js-api"),
    Keys.autoAPIMappings                               :=  autoAPIMappings
  ) ++ (
    Seq(packageJSDependencies, fastOptJS, fullOptJS) map { packageJSKey =>
      Keys.crossTarget in(Compile, packageJSKey) := Keys.baseDirectory.value / ".." / "jvm" / "src" / "main" / "webapp" / "WEB-INF" / "js"
    }
  )

  lazy val root = Project(
      id = "data-retriever-root",
      base = file(".")
  ).aggregate(dataRetrieverJVM, dataRetrieverJS)

  lazy val dataRetriever = CrossProject(
    id = "data-retriever",
    base = file("."),
    crossType = CrossType.Full
  ).settings(
    Defaults.coreDefaultSettings ++ sharedBuildSettings:_*
  ).jvmSettings(
    Defaults.coreDefaultSettings ++ jvmBuildSettings:_*
  ).jsSettings(
    Defaults.coreDefaultSettings ++ jsBuildSettings:_*
  )

  lazy val dataRetrieverJS = dataRetriever.js.enablePlugins(ScalaJSPlugin)

  lazy val dataRetrieverJVM = dataRetriever.jvm.enablePlugins(WarPlugin, SbtTwirl, SbtWeb)
}

http://stackoverflow.com/q/32267018/1274998

@huntc
Copy link
Contributor

huntc commented Apr 16, 2016

Did you try the directWebModules setting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants