Skip to content

Instantly share code, notes, and snippets.

@rpocklin
Last active March 11, 2017 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rpocklin/6389984 to your computer and use it in GitHub Desktop.
Save rpocklin/6389984 to your computer and use it in GitHub Desktop.
Play 2.1 with Scala 2.10 and Jasmine sbt package, with auto-recompilation of LESS (including bootstrap), Jenkins build info, with coffeescript recompilation on (for sources and for specs in coffeescript). Sugar to taste.
import sbt._
import sbt.Keys._
import play.Project._
import sbtbuildinfo.Plugin._
import com.gu.SbtJasminePlugin._
object ApplicationBuild extends Build {
val appName = "your-app-name"
val appVersion = "1.0-SNAPSHOT"
/* Scala Code Coverage Tool; to run it from the Play console:
* scct:test
*
* and view the output (with Firefox, due to cross-site issues) at:
* file://<project-location>/target/scala-2.10/coverage-report/index.html
*/
lazy val scctSettings = Defaults.defaultSettings ++ Seq(ScctPlugin.instrumentSettings : _*)
lazy val sysProps = scala.util.Properties
// Check first for a -D flag, then an environment variable
private def resolveKey(key:String) = {
sysProps.propOrElse( key, sysProps.envOrElse(key, "N/A"))
}
val appDependencies = Seq(
// Add your project dependencies here,
jdbc,
anorm,
"org.scalaz" %% "scalaz-core" % "7.0.3",
"org.mockito" % "mockito-all" % "1.9.5"
)
// Only compile the custom bootstrap.less file and any other *.less file in the stylesheets directory
def customLessEntryPoints(base: File): PathFinder = ( (base / "app" / "assets" / "stylesheets" / "custom" / "custom.less") +++ (base / "app" / "assets" / "stylesheets" * "*.less") )
val main = play.Project(appName, appVersion, appDependencies, settings = Defaults.defaultSettings ++ buildInfoSettings ++ scctSettings)
.settings(
testOptions in Test += Tests.Argument("junitxml", "console"),
// include 3rd-party javascript libraries
unmanagedResources in Compile ++= (file("public/javascripts") ** "*.js").get,
sourceGenerators in Compile <+= buildInfo,
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion),
// Get pertinent build info from Jenkins - these properties are set at build time:
// https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project#Buildingasoftwareproject-below
buildInfoKeys ++= Seq[BuildInfoKey](
"extraInfo" -> resolveKey("EXTRA_INFO"),
"jenkinsBuild" -> resolveKey("BUILD_NUMBER"),
"buildId" -> resolveKey("BUILD_ID"),
"builtBy" -> resolveKey("NODE_NAME"),
"gitBranch" -> resolveKey("GIT_BRANCH"),
"gitVersion" -> resolveKey("GIT_COMMIT")),
buildInfoPackage := "util"
)
.settings( lessEntryPoints <<= baseDirectory(customLessEntryPoints))
.settings(jasmineSettings : _*)
.settings(
// jasmine configuration, overridden as we don't follow the default project structure sbt-jasmine expects
appJsDir <+= baseDirectory / "target/scala-2.10/resource_managed/main/public/javascripts",
appJsLibDir <+= baseDirectory / "public/javascripts",
jasmineTestDir <+= baseDirectory / "test/javascripts/", // specs should be in test/js/specs/exampleSpec.js
jasmineConfFile <+= baseDirectory / "test/javascripts/test.dependencies.js",
// link jasmine to the standard 'sbt test' action. Now when running 'test' jasmine tests will be run
// and after that other Play tests will be executed.
(test in Test) <<= (test in Test) dependsOn (jasmine),
// ensures copy-resources are called (if need updating) before running jasmine task (for coffeescript)
(jasmine) <<= (jasmine) dependsOn (copyResources in Compile),
// auto watch javascript spec directories
unmanagedResources in Test ++= (file("test/javascripts") ** "*.js").get,
// adds coffeescript source files recompilation in ~jasmine
unmanagedResources in Test ++= (file("app/assets/javascripts") ** "*.coffee").get
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment