Play does not ship with any dependency resolution - at least I am not aware of. However, especially when developing webapps needing a lot of external libraries it could be quite handy to take at least this part away from maven and combine it with play. Short disclaimer: I am not the opinion that maven is the perfect tool for this task, but currently it works. Someone with a little bit more ivy know how might be able to build something far better.
Every module you are shipping, should ship with all depedencies resolved. This post should not change anything in this regard. But how you collect the depedencies can be done better, than just copying them together for the module. This is what this post is about.
1. Creating the pom.xml and add your dependencies.
Creating the pom.xml is quite easy. Lets assume for the moment, one of my customers wants freemarker as a template language. So adding the dependency is pretty straightforward.
<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>org.playframework</groupId>
<artifactId>someapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.16</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<outputDirectory>lib/</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
2. Copy all dependencies over the lib/ directory
Adding the dependency is nice, but does not help play to find the needed jar files, when starting up the module. Therefore they must be copied over into the lib/ directory. Cheerfully maven comes with a "dependency" plugin, which can be easily adapted for this task. All you need to call is
mvn dependency:copy-dependencies
That's it. As you do not perform any maven lifecycle operations, you should not have a target/ directory. If so, just do a "mvn clean". Please be aware, that not needed dependencies are not removed from the lib/ directory. The simple solution is always to remove the lib/ directory and then copy the dependencies over again. It is very important not to put the configuration part of the plugin inside an execution block, as this would bind you to the maven lifecycle.
3. Exclude the libraries already included in play
If you want to be sure, not to get in some confusing class loader trouble, because one of your dependencies had a transitive dependency to a library already included in play, we should exclude the libraries used internally by play. All we need to do is do add one line removing the play specific dependencies as done above in the configuration section. I hope this catches all. If not, feel free to add whatever you want. Be aware: This does not save you from double checking, that all your modules use the same library versions.
<excludeArtifactIds>activation,antlr,backport-util-concurrent,bcprov-jdk15,c3p0,cglib-nodep,commons-beanutils,commons-codec,commons-fileupload,commons-httpclient,
commons-lang,commons-logging,core,dom4j,ehcache,ejb3-persistence,ezmorph,filters,geronimo-servlet_2.5_spec,groovy-all,gson,hibernate,hibernate-core,hibernate-commons-annotations,
hibernate-entitymanager,hsqldb,jamon,jaxen,jsr107cache,jta,junit,log4j,lucene-analyzers,lucene-core,mail,oval,snakeyaml,slf4j-api,slf4j-log4j12</excludeArtifactIds>
4. Optionally add play modules in the repository
This step helps you only, when develop inside of a IDE like eclipse, and want to make sure, you've always your jar files available. Even your modules. Why not just adding them to your local repository and feel fine.
mvn install:install-file -Dfile=modules/lib/play-bespin.jar -DartifactId="play-module-bespin" -DgroupId="org.playframework.modules" -Dversion=1.0.0 -Dpackaging=jar
Don't forget to add them to your excludeArtifacts as well in order to not have clashes.
5. Finished
Now that's it for today. I have put the pom.xml into pastebin. Have fun and feel free to comment.