sbt

sbt version

➜  /tmp cat /usr/local/bin/sbt
#!/bin/sh
if [ -f "$HOME/.sbtconfig" ]; then
  echo "Use of ~/.sbtconfig is deprecated, please migrate global settings to /usr/local/etc/sbtopts" >&2
  . "$HOME/.sbtconfig"
fi
exec "/usr/local/Cellar/sbt/0.13.15/libexec/bin/sbt" "$@"

While /usr/local/Cellar/sbt/0.13.15/libexec/bin/sbt is also a shell script wrapper. The real sbt exe and options are configured in file /usr/local/etc/sbtopts.

➜  /tmp cat /usr/local/etc/sbtopts
# ------------------------------------------------ #
#  The SBT Configuration file.                     #
# ------------------------------------------------ #


# Disable ANSI color codes
#
#-no-colors

# Starts sbt even if the current directory contains no sbt project.
#
-sbt-create

# Path to global settings/plugins directory (default: ~/.sbt)
#
#-sbt-dir  /etc/sbt

# Path to shared boot directory (default: ~/.sbt/boot in 0.11 series)
#
#-sbt-boot ~/.sbt/boot  

# Path to local Ivy repository (default: ~/.ivy2)
#
#-ivy ~/.ivy2

# set memory options
#
#-mem   <integer>  

# Use local caches for projects, no sharing.
#
#-no-share

# Put SBT in offline mode.
#
#-offline

# Sets the SBT version to use.
#-sbt-version  0.11.3

# Scala version (default: latest release)
#
#-scala-home <path>        
#-scala-version <version>

# java version (default: java from PATH, currently $(java -version |& grep version))
#
#-java-home <path>

-J-Xmx2G
-J-XX:+CMSClassUnloadingEnabled

The real sbt jar/ bin are under path: /usr/local/Cellar/sbt

➜  sbt  tree -L 2 /usr/local/Cellar/sbt
/usr/local/Cellar/sbt
├── 0.13.15
│   ├── INSTALL_RECEIPT.json
│   ├── bin
│   └── libexec
└── 0.13.9
    ├── INSTALL_RECEIPT.json
    ├── bin
    └── libexec

6 directories, 2 files

➜  0.13.9 tree  /usr/local/Cellar/sbt/0.13.9/ 
/usr/local/Cellar/sbt/0.13.9/
├── INSTALL_RECEIPT.json
├── bin
│   └── sbt
└── libexec
    ├── sbt
    ├── sbt-launch-lib.bash
    └── sbt-launch.jar

2 directories, 5 files
➜  0.13.9 

If you want to use a specific sbt version for the project, configure it in project/build.properties file.

➜  opencity-server git:(master)cat project/build.properties 
sbt.version=1.0.4
➜  opencity-server git:(master)cat project/plugins.sbt     
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.11")
➜  opencity-server git:(master) ✗ tree -L 2 ~/.sbt/
/Users/lucas/.sbt/
├── 0.13
│   ├── staging
│   └── templates
├── 1.0
│   ├── server
│   ├── staging
│   └── zinc
├── boot
│   ├── sbt.boot.lock
│   ├── scala-2.10.2
│   ├── scala-2.10.4
│   ├── scala-2.10.5
│   ├── scala-2.10.6
│   ├── scala-2.11.5
│   ├── scala-2.11.7
│   ├── scala-2.11.8
│   ├── scala-2.12.4
│   └── update.log
├── launchers
│   └── sbt-launch-57d0f04f4b48b11ef7e764f4cea58dee4e806ffd.jar
├── preloaded
│   ├── com.jcraft
│   ├── com.thoughtworks.paranamer
│   ├── jline
│   ├── org.fusesource.jansi
│   ├── org.json4s
│   ├── org.scala-lang
│   ├── org.scala-lang.modules
│   ├── org.scala-sbt
│   ├── org.scala-sbt.ivy
│   ├── org.scala-tools.sbinary
│   ├── org.scalamacros
│   └── org.spire-math
└── repositories

version and dependency

There are many components of a play-framework project, you should take care of when configuring the versions.

application-releated

Firstly, you choose a play-framework verison, usally, the latest one. (the current latest is 2.6.11). Since play-framework is written in Scala, and you also need to write your application code in Scala, you have to choose a Scala version. The latest is 2.12.3. Configure it in build.sbt file.

➜  opencity-server git:(master) ✗ cat build.sbt 
name := """opencity-server"""
organization := "cn.opencity"

version := "1.0-SNAPSHOT"

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

scalaVersion := "2.12.3"

libraryDependencies += guice
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "3.1.2" % Test

// Adds additional packages into Twirl
//TwirlKeys.templateImports += "cn.opencity.controllers._"

// Adds additional packages into conf/routes
// play.sbt.routes.RoutesKeys.routesImport += "cn.opencity.binders._"

build-tool versions

sbt and sbt-plugin for play-framework are used to build the project. There versions are specified under ./project/* dir configuring files.

https://github.com/coursier/coursier#sbt-plugin

Mill play-scala micro-services framework https://www.lagomframework.com/

Getting Started with Play 2.x with IntelliJ

Mill is a new build tool for Scala: it compiles your Scala code, packages it, runs it, and caches things to avoid doing unnecessary work. Mill aims to be better than Scala’s venerable old SBT build tool, learning from it’s mistakes and building upon ideas from functional programming to come up with a build tool that is fast, flexible, and easy to understand and use. This post will explore what makes Mill interesting to a Scala developer who is likely already using SBT

Scala and Play with Gradle