How to integrate Play Framework 2.0 into Gradle build management using Maven dependencies?

Kai Wähner picture Kai Wähner · Apr 24, 2012 · Viewed 11k times · Source

Play framework 2.0 is a full-stack standalone framework for creating web applications. Probably, many people need to integrate it into their build management, nevertheless. Unfortunately, I did not find much information about his.

Here is my use case: I want to create a new project, which uses Scala and Play 2.0. I do NOT want to use sbt. I want to use Gradle, and dependency management should be done via Maven repositories.

I have only found this play module: http://www.playframework.org/modules/maven-1.0/home which supports dependency management via Maven.

I am looking for something like these examples in Grails: https://github.com/grails/grails-gradle-plugin or http://grails.org/doc/latest/guide/commandLine.html#4.5%20Ant%20and%20Maven

Of course, I could write scripts / tasks which call "play console commands". Though, I do not like this solution. Is there a better way to use Gradle / Maven for build management? If this is the only solution, then I would use Gradle, which then calls Play commands (i.e. sbt internally), right? Does this even work, or will there emerge other problems?

Answer

rodion picture rodion · Apr 25, 2012

This is a very tricky business. SBT in Play is used for fetching dependencies, compiling source and templates, and for the SBT incremental compilation + auto-reloading feature. I have written a build.gradle script to resolve all Play 2.0 dependencies and set-up Eclipse or IntelliJ IDEA classpaths, and made it public here.

I will try to implement the compilation later when I have time, but that would require some research. Of course, you can add compile and run tasks that just delegate to SBT but that would require describing all your project dependencies in both SBT and Gradle, which will become difficult to manage.

Edit:

I have updated the sample build.gradle file. I have added playCompile and playClean tasks that should help in a CI environment. The playCompile task does the following:

  1. Copy all user dependencies (defined in compile configuration) to lib/ folder. This works because Play will kindly pick up all jars from under lib/.
  2. Execute play compile command to compile all sources, templates and other Play framework stuff.

You can use cleanCopyPlayLibs and playClean to remove the output of the above commands, respectively.

Note that there appears to be a strange problem (bug?) on Windows, which means that even if play compile fails, gradle will tell you it succeeded.

Reply to comment:

I think you are simply missing

repositories{
  mavenCentral()
}

in your file. Check this doc out.