Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the "grails clean" script actually do?

Tags:

I'm curious about the grails clean command. Once I imported a wrong package into a domain class, It was java.util.regex. I used it to do a regex replace command, but it turns out that everything was unchanged so that I supposed my regex was wrong. But I left it there for future refinement.

The web-app in my localhost functioned normally but then other programmers told me that they got compiling errors when they tried to compile my code. I shutdown grails and then start it again, but it still ran properly. Only after runnning grails clean the compiling error appeared.

So it seems the application just ignored my changes in the first place. In the documentation, they say:

In case your Grails application has been screwed and comes up with mysterious error messages try:

grails clean

I'm a bit confused about this "mysterious" thing. So what does grails clean actually do? What kinds of resources will not get compiled again, unless grails clean is called?

like image 994
Hoàng Long Avatar asked Dec 31 '10 04:12

Hoàng Long


People also ask

What does grails clean do?

Purpose. The clean command deletes all compiled resources from the application. Since Groovy is a compiled language, as with Java, this is sometimes useful to clear old instances of classes and ensure correct compilation.

How do you use grails?

Go to start.grails.org and use the Grails Application Forge to generate your Grails project. You can choose your project type (Application or Plugin), pick a version of Grails, and choose a Profile - then click "Generate Project" to download a ZIP file. No Grails installation necessary!


2 Answers

The clean script deletes compiled classes and property files and other non-source resources that were copied to the classes dir, and also other stuff like test reports.

The problem that you're seeing is with incremental compilation. It's fairly reliable in general but can fail with Java, and is unfortunately more likely with Groovy since it's a dynamic language. It's hard to detect the full scope of a change in one class on all other classes, and sometimes changes get missed. If you're lucky it's obvious that something's wrong but sometimes it can take a while wondering why some seriously strange behavior is happening.

So the best thing to do is always do a full compile, whether it's pure Java or a mix of Groovy and Java. Since this is expensive (especially with larger projects) it's sufficient to use incremental compilation as much as possible, but occasionally force a full compile with grails clean.

like image 158
Burt Beckwith Avatar answered Sep 20 '22 01:09

Burt Beckwith


grails clean 

The clean command deletes all compiled resources from the application. but not temporary files.

grails clean-all 

The clean-all command deletes all compiled resources as well as work directory, which contains project-specific temporary files.

Since Groovy is a compiled language, as with Java, this is sometimes useful to clear old instances of classes and ensure correct compilation. It's also a good idea to run these scripts before running tests or creating a WAR file to ensure a full compilation occurs.

like image 45
Armando Prieto Avatar answered Sep 22 '22 01:09

Armando Prieto