Fork me on GitHub

Quickstart Guide

This page explains how to use the play2-maven-plugin to build your Play 2 application using Maven.

Prerequisites

Create a Play 2 application using the play command:

play new myFirstApp

This command creates the Play 2 application. Obviously it's not required if you already have an existing application.

Mavenization

At the root of the created project, create a pom.xml file with the following content:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>your.group.id</groupId>
    <artifactId>your.artifact.id</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>myFirstApp</name>

    <packaging>play2</packaging>

    <properties>
        <play.version>2.1.0</play.version>
    </properties>

        <repositories>
            <repository>
                <id>typesafe</id>
                <url>http://repo.typesafe.com/typesafe/releases/</url>
            </repository>
        </repositories>

        <dependencies>
            <!--
            Add your dependencies here (modules, libraries...).
            Dependencies in the compile scope will be embedded within the application.
            -->


            <!-- Play Framework Dependencies -->
            <dependency>
                <groupId>play</groupId>
                <artifactId>play_2.10</artifactId>
                <version>${play.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>play</groupId>
                <artifactId>play-test_2.10</artifactId>
                <version>${play.version}</version>
                <scope>provided</scope>
            </dependency>

        </dependencies>

    <build>
        <!-- Play source directory -->
        <sourceDirectory>app</sourceDirectory>
        <testSourceDirectory>test</testSourceDirectory>

        <plugins>

            <plugin>
                <groupId>de.akquinet.innovation.play2</groupId>
                <artifactId>play2-maven-plugin</artifactId>
                <version>1.2.2-SNAPSHOT</version>
                <extensions>true</extensions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>

        </plugins>

    </build>

</project>

That's it !

Usage

Before starting, be sure to have the play executable in your path or to have defined the PLAY2_HOME system variable used by the plugin to find the Play 2 SDK (or check the next section). As shown in the previous pom file, the packaging of your project must be play2.

To define the PLAY2_HOME variable on Mac/Linux use:

export PLAY2_HOME=...
# or
mvn clean install -DPLAY2_HOME=...

To build the application, simply run:

mvn clean install

To compile and test only:

mvn test

To package the application without running the tests:

mvn package -DskipTests

To debug the application:

mvn play2:debug

Finally, to run the application:

mvn play2:run

Using the regular Maven structure

By default the plugin is configured to use the Play directory structure. But it can be configured to use the Maven structure. Check this page for more information.

Setting Play 2 location from the pom file

The PLAY2 location can also be defined in the pom.xml file such as in:

  <plugin>
    <groupId>de.akquinet.innovation.play2</groupId>
    <artifactId>play2-maven-plugin</artifactId>
    <version>1.2.2-SNAPSHOT</version>
    <extensions>true</extensions>
      <configuration>
        <play2Home>some/path/to/play-2.0</play2Home>
      </configuration>
  </plugin>

The plugin is checking in this order:

  • the PLAY2_HOME system variable (set with -DPLAY2_HOME=...)
  • the play2Home setting
  • the PLAY2_HOME environment variable

If PLAY2_HOME is not define, the plugin use the system PATH, and looks for the play or play.bat executable.