About Hubert Ikkink

My name is Hubert A. Klein Ikkink also known as mrhaki. I work at the great IT company JDriven. Here I work on projects with Groovy & Grails, Gradle and Spring. At JDriven we focus on SpringSource technologies. All colleagues want to learn new technologies, support craftmanship and are very eager to learn. This is truly a great environment to work in.

Grails Goodness: Cleaning Up

When we use for example the compile or war command Grails will create files and stores them by default in the project’s working directory. The location of the project working directory can be customized in our grails-app/conf/BuildConfig.groovy configuration file. We remove the generated files with the Grails clean command. This command will remove all compiled class files, the WAR file, cached scripts and test reports. But this doesn’t remove all files in the project working directory. For example plugins or a temporary web.xml file, which are stored in the project working directory are not removed. We must use the clean-all command to also remove those files from the project working directory completely.

Let’s take a look at the default settings in our grails-app/conf/BuildConfig.groovy configuration file when we create a new Grails application:

// File: grails-app/conf/BuildConfig.groovy
...
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.work.dir = "target/work"
...

After we run the war command we see the following contents in our target directory:

$ grails war
| Compiling 10 source files
 
| Compiling 142 source files
 
| Done creating WAR target/cleanCmd-0.1.war
$ ls target/
classes   cleanCmd-0.1.war stacktrace.log  work

Let’s first run the clean command and check the contents of the target directory again:

$ grails clean
| Application cleaned.
$ ls target/
stacktrace.log work

Notice the target/work directory still exists. We now run clean-all and examine the contents of the target directory:

$ grails clean-all
| Application cleaned.
$ ls target/
stacktrace.log

Now the work directory is removed as well.

We can also write our own scripts to for example only remove the generated WAR file with a clean command. With the following script we add the command clean-war to our application, which will delete the generated WAR file from our project:

// File: scripts/CleanWar.groovy
includeTargets << grailsScript("_GrailsClean")
 
setDefaultTarget("cleanWarFile")

We can use the targets cleanCompiledSources, cleanTestReports and cleanWarFile in our own scripts.

  • Code written with Grails 2.3.5

 

Reference: Grails Goodness: Cleaning Up from our JCG partner Hubert Ikkink at the JDriven blog.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

Leave a Reply


× 4 = twenty four



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close