Attach Source Code using SBT / Play Framework

Attaching Source Code using SBT / Play Framework for Java

SBT 0.13 and above / Play 2.4.1 and Above

To resolve issues relating to build code running on version 0.13 and above refer, to the migration article at Migration from 0.12.x

To tweak your compile mappings (for Play 2.4.1 and above):

  • Before the project definition, add the following line:
inconfig(Compile)(mappings in packageBin ++= Defaults.sourceMappings) 

Example of build.sbt:

inConfig(Compile)(mappings in packageBin ++= Defaults.sourceMappings)
lazy val root = (project in file(".")).enablePlugins(PlayScala)

SBT 0.9 - 1.2 / Play 2.4.0 and Below

To attach source code to .jar with SBT:

  1. Add the following line to the build.sbt file:
unmanagedResourceDirectories in Compile <+= baseDirectory( _ / "app" )
  1. In a Maven-like project structure, replace "src" with "src/main/scala" and "src/main/java":
unmanagedResourceDirectories in Compile <+= baseDirectory( _ / "src/main/scala" )
  1. Restart the OverOps Collector for the changes to take effect.
    Example of an sbt.build:
name := "hello"
version := "1.0"
scalaVersion := "2.9.2"
resolvers += "twitter-repo" at "http://maven.twttr.com" libraryDependencies ++= Seq("com.twitter" % "finagle-core" ...
unmanagedResourceDirectories in Compile <+= baseDirectory( _ / "src/main/scala" )
unmanagedResourceDirectories in Compile <+= baseDirectory( _ / "app" )

Example of a build.scala:

lazy val defaultSettings =
buildSettings ++
Seq(
parallelExecution in Test := false,
fork in Test := true,
unmanagedResourceDirectories in Compile <+= baseDirectory( _ / "src/main/scala" )
)