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?
Gradle can consume dependencies available in the local Maven repository.
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.
Short answer: yes. There's no conflict between having two independent build scripts for the same project, one in Maven and one in 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.
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:
compile
configuration) to lib/
folder. This works because Play will kindly pick up all jars from under lib/
.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.
Good news, as of Gradle 2.7 there is an official play plugin: https://docs.gradle.org/current/userguide/play_plugin.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With