Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 473
Kai Wähner Avatar asked Apr 24 '12 14:04

Kai Wähner


People also ask

Can Gradle use Maven dependency?

Gradle can consume dependencies available in the local Maven repository.

How do I add a dependency in Gradle?

To add a dependency to your project, specify a dependency configuration such as implementation in the dependencies block of your module's build.gradle file.

Can you mix Maven and Gradle?

Short answer: yes. There's no conflict between having two independent build scripts for the same project, one in Maven and one in Gradle.

What is dependencies in build Gradle?

Dependencies refer to the things that supports in building your project, such as required JAR file from other projects and external JARs like JDBC JAR or Eh-cache JAR in the class path. Publications means the outcomes of the project, such as test class files, build files and war files.


2 Answers

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.

like image 79
rodion Avatar answered Sep 22 '22 05:09

rodion


Good news, as of Gradle 2.7 there is an official play plugin: https://docs.gradle.org/current/userguide/play_plugin.html

like image 25
mana Avatar answered Sep 21 '22 05:09

mana