Java Reference
In-Depth Information
Turning now to the _GrailsClean script, let me highlight a couple of small sections
from it:
includeTargets << grailsScript("_GrailsEvents")
target (cleanAll: "Cleans a Grails project") {
clean()
cleanTestReports()
grailsConsole.updateStatus "Application cleaned."
}
target (clean: "Implementation of clean") {
depends(cleanCompiledSources, cleanWarFile)
}
Theresemblance toAntisnotaccidental. Gantscriptscontaintargets,andtargetscanbein-
vokedasthoughtheyweremethodcalls. Herethetargetdefinedwiththename cleanAll
invokes two other tasks ( clean and cleanTestReports ) and then invokes the up-
dateStatus method on the predefined grailsConsole object.
The clean task uses the depends method (again analogous to the same functionality
in Ant) to make sure that the cleanCompiledSources and cleanWarFile tasks
are invoked when the clean task is invoked. Here's a snippet from the cleanCom-
piledSources task:
target (cleanCompiledSources: "Cleans compiled Java and Groovy sources") {
def webInf = "${basedir}/web-app/WEB-INF"
ant.delete(dir:"${webInf}/classes")
ant.delete(file:webXmlFile.absolutePath, failonerror:false)
ant.delete(dir:"${projectWorkDir}/gspcompile", failonerror:false)
Thetaskgoesontodeletemanymoreitems,delegatingtoaninternal AntBuilder object
in each case. The cleanWarFile task shows how you can mix in Groovy logic code in-
side a script:
target (cleanWarFile: "Cleans the deployable .war file") {
if (buildConfig.grails.project.war.file) {
warName = buildConfig.grails.project.war.file
}
else {
def fileName = grailsAppName
def version = metadata.'app.version'
if (version) {
fileName += "-$version"
Search WWH ::




Custom Search