When I create a Grails app, it comes with some default files in the web-app
directory:
$ find web-app web-app web-app/css web-app/css/errors.css web-app/css/main.css web-app/css/mobile.css web-app/images web-app/images/apple-touch-icon-retina.png web-app/images/apple-touch-icon.png web-app/images/favicon.ico web-app/images/grails_logo.jpg web-app/images/grails_logo.png web-app/images/leftnav_btm.png web-app/images/leftnav_midstretch.png web-app/images/leftnav_top.png web-app/images/skin web-app/images/skin/database_add.png web-app/images/skin/database_delete.png web-app/images/skin/database_edit.png web-app/images/skin/database_save.png web-app/images/skin/database_table.png web-app/images/skin/exclamation.png web-app/images/skin/house.png web-app/images/skin/information.png web-app/images/skin/shadow.jpg web-app/images/skin/sorted_asc.gif web-app/images/skin/sorted_desc.gif web-app/images/spinner.gif web-app/images/springsource.png web-app/js web-app/js/application.js
(META-INF
and WEB-INF
folders snipped from output)
These files create clutter in my app, and also use the common directory names css
, images
, and js
, that I'm likely to want to use for my own resources.
In the past I've manually deleted these, but they return by themselves after running grails upgrade
, overwriting my own files in the process.
I can't see any reason to keep these files around. Is there something I'm missing? If not, how can I get rid of them and make sure they never come back?
According to Burt Beckwith, the correct solution to this is to not use grails upgrade
. Apparently, this is no longer the recommended way to upgrade a Grails application, because it really only does two important things, and that is to bump the version and then clean the app so everything is re-downloaded.
From that posting, the recommended process for smaller version changes is:
- Edit
application.properties
and update the version.- Then run
grails clean
to clear outdated files.- Finally run
grails compile
and it'll ask you if you want to upgrade the Hibernate and Tomcat plugins (if they're listed inBuildConfig.groovy
).You can also manually delete the old plugins in the work folder under the
$HOME/.grails
folder.
Another tip Burt provides is:
It's even simpler if you add
grails.project.work.dir = 'target'
toBuildConfig.groovy
. Then all your plugins will be there and you can just delete the whole target folder and all the plugins will be reinstalled and/or updated, and all the classes will be recompiled.
The process for major updates (such as upgrading a 1.x app to a 2.x app), is a little more involved:
- create a new empty app in the new version of Grails
- create a new empty app in the old version of Grails
- diff your current app with the empty old-version app - this will tell you what you deleted, added, and changed. Copy new files over, delete stuff that should be deleted, and re-do the changes you made. Be sure to read the release notes and upgrade information for the intermediate Grails versions so you know how to make the new changes - e.g. HSQLDB -> H2 in DataSource.groovy, etc. Don't just blindly make the same changes.
Hopefully this will be documented eventually in the official docs, as it makes sense, since the upgrade process is too complicated to effectively be automated.
This doesn't, however, explain how to deal with new applications. Of course, you could simply just delete all Grails-specific files (which I recommend unless you use scaffolding).
Another option is to move all the Grails-specific files into some subdirectory, then manually modify (and/or rename) the main
layout, CSS files and resources links to point to these new locations.
If you still want to use scaffolding, I recommend copying the main.gsp
layout to scaffolding.gsp
, and to create a new resources module just for scaffolding that contains all the default CSS and JS requirements. Then run grails install-templates
, which will provide you with the basic view templates for scaffolding. You can then easily change the layout and add or update the correct resources module.
Finally, once you've got your base application the way you want, zip it up and save it for later. That's at least an easy way to only have to do all this once.
Note
After installing the templates, you probably won't need theartifacts
orwar
template folders, located undersrc/templates
. Unless you know you use them, they should be deleted.
As a final note, make sure you use a good, robust version control system, such as git or mercurial. This will make it easy to see what's been modified if you accidentally run grails upgrade
, and discard or roll back files you'd rather not change. With a decent IDE or GUI, you can usually fix this in a few clicks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With