Skip to content

wangyizhuo/play-maven

Repository files navigation

Maven support

The Maven module enables maven support for your application. It adds a pom.xml in your project and deploys a play-parent pom in your local Maven repository.
Thus, libraries are copied to /lib folder.

Moreover, this module has the ability to create a war package of a Play! application using the ‘mvn package’ command’.
The Play! applciations can now be used in you Continuous Integration (CI) system.

What is supported?

  • A standard pom.xml can be installed in your Play! application.
  • Libraries dependencies are handled by your pom and are downloaded to your /lib folder in a single command.
  • Cleaning libraries in the /lib folder is supported in a single command.
  • Packaging your Play! application to a war using Maven is now possible (using only mvn package).

Getting started

First, you need to download and install Apache Maven.

Finally, you need to install the play-maven module:

# play install maven

Setting up the Maven module

Start by creating a new application in the classical way.

# play new test-maven

Then edit the conf/application.conf file to enable the Maven module:

# Additional modules
# ~~~~~
# A module is another play! application. Add a line for each module you want
# to add to your application. Module paths are either absolutes or relative to
# the application root.
#
module.maven=${play.path}/modules/maven

At this moment, if you are working with Eclipse, do not forget to update your .classpath :

# play ec

You now have to install play-parent in your repository and get a pom.xml in your Play! application :

# play mvn:init

This command installs play-parent pom in your local repository (ex : ~/.m2/repository) and copies the ‘skeleton’ pom from the play-module to your application.

Edit your pom.xml to change your groupId, artifactId, version, name and description.

Launch an update to retrieve Play! libraries and check there is no error :

# play mvn:up

That’s it ! Your application is Maven-compliant.
The following maven commands are now working :

# mvn clean // be careful, it deletes your /lib folder
# mvn compile
# mvn package // will create a war file

play-maven specific commands

# play mvn:init

Installs play-parent project (a Maven pom project) into local Maven repository. Then creates the appropriate pom.xml. After this step, you can add your dependencies to pom.xml.

# play mvn:update // or play mvn:up

Retrieves all defined dependencies and then it copies them into your /lib folder.

# play mvn:refresh // or play mvn:re

Clears your app/lib folder first, then it executes play mvn:up.

Known issues

As long as Play! framework Issue #359 is not resolved, ‘target’ directory is embedded inside the generated war.
You have to remove it manually after packaging your war (because target directory contains Play! runtime).

Use case

The expected use case of this module:

  • add dependencies to pom.xml
  • run play mvn:up or play mvn:re
  • run play ec to update Eclipse environment to setup classpath for Eclipse, etc.
  • develop and test

For packaging, I created a simple shell script, since all jars will be found in lib folder, and using shell script is faster and more flexible.

Limitations

And maven commands (especially mvn commands) are not supported, includes.:

  • mvn compile
  • mvn package
  • mvn install