Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: v1.2.3
Fetching contributors…

Cannot retrieve contributors at this time

346 lines (313 sloc) 13.095 kb
import org.gradle.api.tasks.testing.ForkMode
import org.gradle.util.ClasspathUtil
import org.gradle.api.tasks.compile.GroovyCompile
defaultTasks "libs"
// Groovy plugin settings.
sourceCompatibility = "1.5"
targetCompatibility = "1.5"
archivesBaseName = 'grails'
groovySrcDirNames = [ "commons", "groovy", "persistence", "scaffolding", "tiger", "web" ]
// This manifest gets added to all the Grails JARs we create. "version"
// comes from
"Built-By": System.getProperty(""),
"Implementation-Title": "Grails",
"Implementation-Version": version,
"Implementation-Vendor": "")
archivesBaseName = "grails"
// The scripts are compiled to a different directory from all the other
// source files.
scriptClassesDirTask = dir("$buildDirName/script-classes")
// All the libraries that Grails depends on.
dependencies {
addFlatDirResolver('lib', new File(rootDir, 'lib'))
clientModule(['groovy'], ":groovy-all:1.6.8") {
clientModule(":ant:1.7.0") {
dependencies(":ant-junit:1.7.0", ":ant-launcher:1.7.0")
compile ":ant:1.7.0",
testCompile ":cglib-nodep:2.1_3",
testRuntime ":slf4j-api:1.5.2",
jsp21 ":jsp-api:2.1"
* Compiles the Gant scripts to a custom target directory using Groovyc.
createTask("compile-scripts", dependsOn: [ "compile", scriptClassesDirTask ]) {
ant {
taskdef(name: "groovyc",
classname: "org.codehaus.groovy.ant.Groovyc",
classpath: dependencies.antpath("groovy"))
groovyc(destdir: scriptClassesDirTask.dir, encoding: "UTF-8", fork: true, classpath: dependencies.antpath("compile")) {
classpath {
pathelement(location: classesDir)
pathelement(location: "$rootDir/lib/ant-junit-1.7.0.jar")
pathelement(location: "$rootDir/lib/jetty-6.1.12.jar")
pathelement(location: "$rootDir/lib/jetty-plus-6.1.12.jar")
pathelement(location: "$rootDir/lib/jetty-util-6.1.12.jar")
pathelement(location: "$rootDir/lib/svnkit-1.2.0.jar")
pathelement(location: "$rootDir/lib/xalan.jar")
pathelement(location: "$rootDir/lib/xercesImpl-2.9.0.jar")
src(path: "$rootDir/scripts")
* Packages all the resource files for new Grails applications and
* plugins into a set of JAR files. Basically they contain the starting
* directory and file structure.
createTask("jar-app-files", dependsOn: [ "compile" ]) {
// Clear out the existing JAR files first.
ant.delete {
fileset(dir: buildDir, includes: "grails-*-files.jar")
// Package up the files that are shared by both applications and plugins.
ant.jar(destfile: "$buildDir/grails-shared-files.jar") {
fileset(dir: "$rootDir/src/grails/templates/ide-support/eclipse")
fileset(dir: "$rootDir/src/grails", includes: "build.xml")
fileset(dir: "$rootDir/src/grails/templates/ide-support/textmate", includes: "project.tmproj")
zipfileset(dir: "$rootDir/src/war", prefix: "web-app") {
include(name: "WEB-INF/applicationContext.xml")
include(name: "WEB-INF/applicationContext.xml")
include(name: "WEB-INF/sitemesh.xml")
include(name: "WEB-INF/tld/*.tld")
fileset(dir: "$rootDir/src/grails") {
include(name: "grails-app/conf/DataSource.groovy")
include(name: "grails-app/conf/UrlMappings.groovy")
// Package up the files that are exclusive to applications.
ant.jar(destfile: "$buildDir/grails-app-files.jar") {
zipfileset(dir: "$rootDir/src/war", prefix: "web-app") {
exclude(name: "WEB-INF/**")
fileset(dir: "$rootDir/src/grails") {
include(name: "grails-app/**")
exclude(name: "grails-app/taglib/**")
exclude(name: "grails-app/utils/**")
exclude(name: "grails-app/conf/DataSource.groovy")
exclude(name: "grails-app/conf/UrlMappings.groovy")
// Package up the files that are exclusive to plugins.
ant.jar(destfile: "$buildDir/grails-plugin-files.jar") {
fileset(dir: "$rootDir/src/grails/templates/plugins")
* Runs the DefaultUrlMappingEvaluatorsTests test case on its own. It
* seems to fail for no apparent reason with Gradle. Works fine from
* the Ant build.
createTask("test-single", dependsOn: "testCompile") {
ant.mkdir(dir: testResultsDir)
ant.junit(fork: true, forkmode: "once", clonevm: true) {
sysproperty(key: "grails.cli.testing", value: true)
jvmarg(value: "-server")
jvmarg(value: "-Xmx1G")
jvmarg(value: "-Xms256m")
jvmarg(value: "-XX:MaxPermSize=256m")
classpath(path: dependencies.antpath("testRuntime"))
classpath(location: classesDir)
classpath(location: testClassesDir)
// classpath(location: "$rootDir/target/test-classes")
formatter(type: "xml")
test(todir: testResultsDir, name: "org.codehaus.groovy.grails.web.mapping.DefaultUrlMappingEvaluatorTests")
// After the source files have been compiled, we...
compile.doLast {
// Compile the JSP 2.1 specific classes with the "jsp-api-2.1.jar"
// library on the classpath.
dependencies.linkConfWithTask('jsp21', 'jspCompile');
dependencies.linkConfWithTask('compile', 'jspCompile');
GroovyCompile jspCompile = createTask('jspCompile', type: GroovyCompile).configure {
groovySourceDirs = ["$srcRoot/jsp21" as File]
groovyClasspath = dependencies.resolve("groovy")
destinationDir = classesDir
// ...create a manifest file in the "classes" directory using Ant's
// manifest task. It replicates the manifest included in the dist
// JARs.
def manifestDir = new File(classesDir, "META-INF")
ant.mkdir(dir: manifestDir)
ant.manifest(file: "$manifestDir/MANIFEST.MF") {
manifest.manifest.mainAttributes.each { key, value ->
attribute(name: key, value: value)
// ...copy all the "*.properties" files from the source directories
// to "classes". Normally the files would be in a "resources"
// directory and we could leave Gradle to do this automatically.
ant.copy(todir: classesDir) {
groovySrcDirs.each { dir ->
fileset(dir: dir, includes: "**/*.properties")
testCompile {
// Because of the layout of Grails, we can't simply specify a list of
// directory names for the test sources. This is because Gradle's Java
// plugin expects them to be under "src", which they're not. So we
// update the test source directories manually here.
groovySourceDirs = [
new File("$rootDir/test/commons"),
new File("$rootDir/test/groovy"),
new File("$rootDir/test/persistence"),
new File("$rootDir/test/scaffolding"),
new File("$rootDir/test/tiger"),
new File("$rootDir/test/web") ]
groovyOptions.forkOptions.memoryMaximumSize = '1G'
test {
// These directories need to be on the classpath for the tests it
// seems. Perhaps the relevant files could be moved to "resources"
// in the future? Also, the JDK tools.jar is required for some of
// the CLI tests because they need to run 'native2ascii'.
new File(rootDir, "src/war/WEB-INF"),
new File(rootDir, "src/grails/grails-app/utils"),
new File(rootDir, "test/commons"),
new File(rootDir, "test/groovy"),
new File(rootDir, "test/persistence"))
// tools jar does not exists on every OS (e.g. OS X))
if (ClasspathUtil.toolsJar) { unmanagedClasspath(ClasspathUtil.toolsJar) }
// We don't want to run all the classes under "test-classes" as tests,
// so we set up the inclusions and exclusions here. We also need to
// pass arguments to the forked JUnit processes, so we do that here too.
testName = System.getProperty("test") ?: '*'
includes = ["**/${testName}Tests.class"]
exclude("**/Abstract*", "**/TransactionalServiceReloadTests*")
forkMode: ForkMode.ONCE,
jvmArgs: [ "-Dgrails.cli.testing=true", "-Xmx1G", "-Xms256m", "-XX:MaxPermSize=256m" ])
// Clean the test results and reports before each test run.
test.doFirst {
// Clean the reports.
ant {
delete(dir: testResultsDir)
delete(dir: reportsDir)
// The scripts must be compiled and the application/plugin resources
// packaged before we can build the distribution JARs.
libs {
dependsOn("compile-scripts", "jar-app-files")
jar(appendix: "core") {
fileSet(dir: classesDir) {
files(new File(rootDir, ""))
destinationDir = distsDir
jar(appendix: "bootstrap") {
fileSet(dir: classesDir) {
fileSet(dir: "$rootDir/conf") {
destinationDir = distsDir
jar(appendix: "scripts") {
fileSet(dir: scriptClassesDirTask.dir)
destinationDir = distsDir
jar(appendix: "resources") {
fileSet(dir: buildDir) {
fileSet(dir: rootDir) {
destinationDir = distsDir
Jump to Line
Something went wrong with that request. Please try again.