To some degree, you can configure Play to use a Maven-like directory structure. This page explains how this can be configured.
Open the project/Build.scala file, and change the appName and appVersion variable definition to:
def fromEnv(name: String) = System.getenv(name) match {
case null => None
case value => Some(value)
}
val appName = fromEnv("project.artifactId").getOrElse("my-app")
val appVersion = fromEnv("project.version").getOrElse("1.0-SNAPSHOT")
We will now see how to configure the project to have our Java sources in src/main/java, Scala sources in src/main/scala, and tests in src/test/java and src/test/scala. In the project/Build.scala file, update the Play Project definition to:
val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
// Source folders
sourceDirectory in Compile <<= baseDirectory / "src/main/java",
sourceDirectory in Test <<= baseDirectory / "src/test/java",
scalaSource in Compile <<= baseDirectory / "src/main/scala",
scalaSource in Test <<= baseDirectory / "src/test/scala",
javaSource in Compile <<= baseDirectory / "src/main/java",
javaSource in Test <<= baseDirectory / "src/test/java"
)
Let's now see how to configure src/main/conf to be the Play 2 conf folder. Add to the Play Project settings the following lines:
confDirectory <<= baseDirectory / "src/main/conf",
resourceDirectory in Compile <<= baseDirectory / "src/main/conf"
You can move the application.conf, routes and others configuration files into this folder.
This is not required if you are using play 2.1.0+
Changing the public folder is a bit more complex as it requires two manipulations. First, in project/Build.scala, in the project settings add:
playAssetsDirectories := Seq.empty[File],
// The route file also needs to be updated...
playAssetsDirectories <+= baseDirectory / "src/main/resources"
Then open the route file and change the reference to /public to:
# Map static resources from the /src/main/resources folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/src/main/resources", file)
Set the directory where the distribution is built with:
distDirectory <<= baseDirectory / "target/dist",
However, only target/dist
is supported by the plugin.
Play is using the lib folder to store unmanaged dependencies (i.e. dependencies not managed by SBT). The plugin populates this folder with the Maven dependencies declared in the project. By default, to be compatible with the default Play layyout, it use the lib directory. However you can change it. In order to move this location to target/lib you need to edit two files.
First, open the project/Build.scala file and in the project settings add:
unmanagedBase <<= baseDirectory { base => base / "target/lib" }
Then, open the project pom.xml file and change the play2-maven-plugin configuration to:
<plugin>
<groupId>de.akquinet.innovation.play2</groupId>
<artifactId>play2-maven-plugin</artifactId>
<version>1.2.2-SNAPSHOT</version>
<extensions>true</extensions>
<configuration>
<lib>target/lib</lib>
</configuration>
</plugin>