Reputation: 23
Is there a way to replace the Grails default Config.groovy, BuildConfig.groovy, DataSource.groovy, etc. configuration files that are generated/copied when running grails create-app? I have several apps that all use the same or very similar configurations so I end up doing a lot of copying and pasting when starting a new one.
I looked into using external configuration files which might work, but I'd also like to replace the spring/resources.groovy and some of the views and css/js/images files as well which wouldn't be able to be done that way.
I saw where these files are located in $GRAILS_HOME/src, but changing those directly doesn't affect create-app (I'm assuming I'd need to rebuild grails for that to take affect).
Thank you!
Upvotes: 2
Views: 478
Reputation: 75671
There is a way but it's a bit involved, and completely undocumented, so this will be our little secret.
The create-app
and create-plugin
scripts are actually quite simple. They create a new empty directory and extract some jar files from GRAILS_HOME/grails-resources-<version>.jar
that contain the various project files, and unpack those into the project directory. Then integrate-with --eclipse
is run to create IDE files for GGTS and for create-app
the wrapper
script is run to create grailsw
, etc. unless you use the --skip-wrapper
flag.
Towards the end of 2.3.0 development I added a check in the scripts for customized version of these jars and if one or more are found, they're used instead of the stock jars. To use this, create a folder in $HOME/.grails/<version>
named app-templates
. So for Grails 2.4.3 that'd be $HOME/.grails/2.4.3/app-templates
. To avoid accidentally deleting this directory I'd actually create a symlink with that name pointing to a separate directory (e.g. ln -s /path/to/app-templates.2.4.3 ~/.grails/2.4.3/app-templates
, but that's optional. You could also use symlinks to share one set of override jars for multiple version of Grails.
Unzip $GRAILS_HOME/dist/grails-resources-2.4.3.jar
and you'll have 5 jar files: grails-app-files.jar
(app-specific files), grails-integration-files.jar
(files for the integrate-with
script, e.g. Eclipse project files, IDEA project files, etc.), grails-plugin-files.jar
(plugin-specific files), and grails-shared-files.jar
(files used by both apps and plugins). Additionally you'll have a grails-wrapper-support.jar
but this isn't something you'd typically want to customize.
Unzip each of the 4 jar files and make whatever changes you want. Some of the changes I tend to do are to delete a lot of comments from conf files, move URLMappings.groovy
from the shared jar to the app jar since it's rarely needed in plugins, move DataSource.groovy
from the shared jar into both the app and plugin jars and strip out most of the one that'll be used in plugins, and a few other changes. You can delete files, move them around between the jars, and add new files if you like.
Upvotes: 5