public
Last active

Setting up Play 2.0 in build.gradle

  • Download Gist
gistfile1.groovy
Groovy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
apply plugin: 'java'
apply plugin: 'scala'
// For those using Eclipse or IntelliJ IDEA
apply plugin: 'eclipse'
apply plugin: 'idea'
 
def findPlay20(){
def pathEnvName = ['PATH', 'Path'].find{ System.getenv()[it] != null }
for(path in System.getenv()[pathEnvName].split(File.pathSeparator)){
for(playExec in ['play.bat', 'play.sh', 'play']){
if(new File(path, playExec).exists()){
project.ext.playHome = path
project.ext.playExec = new File(path, playExec)
return
}
}
}
throw new RuntimeException("""'play' command was not found in PATH.
Make sure you have Play Framework 2.0 installed and in your path""")
}
 
findPlay20()
 
repositories{
mavenCentral()
 
// Play framework manages its own dependencies in a local Ivy repo
ivy{
def repoDir = "${playHome}/repository/local/"
url repoDir
ivyPattern "${repoDir}/[organisation]/[module]/[revision]/[type]s/[artifact].[ext]"
artifactPattern "${repoDir}/[organisation]/[module]/[revision]/[type]s/[artifact].[ext]"
layout 'pattern'
}
}
 
configurations{
//Configuration containing sbt generated .class files
//This is needed for IDEs, because they cannot compile
//play templates by themselves.
playManaged
 
//Libraries needed at compilation time but not to be
//exported as part of the distribution
provided
}
 
dependencies{
// User defined libraries (will be copied to lib/ before `play compile`)
compile 'group:name:0.1'
 
// Default Gradle Scala plugin settings below (see Scala plugin page for up-to-date info)
 
// Libraries needed to run the scala tools
scalaTools 'org.scala-lang:scala-compiler:2.9.1'
scalaTools 'org.scala-lang:scala-library:2.9.1'
 
// Libraries needed for scala API
provided 'org.scala-lang:scala-library:2.9.1'
 
// Play 2.0 Framework public API
provided group: 'play', name: 'play_2.9.1', version: '2.0', configuration: 'compile'
 
playManaged files('target/scala-2.9.1/classes_managed')
}
 
task copyPlayLibs(type: Copy){
from configurations.compile
into 'lib'
}
 
task "playCompile" (type: Exec, dependsOn: copyPlayLibs) {
commandLine playExec, 'compile'
}
 
task "playClean" (type: Exec) {
commandLine playExec, 'clean'
}
 
sourceSets.main{
java.srcDir 'app'
compileClasspath += configurations.provided
}
 
// optional: if using 'idea' plugin
idea {
module{
scopes.COMPILE.plus += configurations.playManaged
scopes.PROVIDED.plus += configurations.provided
}
}
 
// optional: if using 'eclipse' plugin
eclipse {
classpath {
plusConfigurations += configurations.playManaged
plusConfigurations += configurations.provided
}
}

cool, extactly this i have been looking for! thanks a lot

Mister devprof was faster

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.