
Manual Maven Grails update
20 October, 2010Recently I had to upgrade a Grails application from 1.2.2 to 1.3.4 at a client site. They use maven heavily and so use the grails maven plugin.
The Grails Maven plugin integration is imperfect. If you need to upgrade to a newer version of grails, there are some manual steps required.
Firstly, edit your POM to update the versions to the required version of grails/ groovy :-
- groovy-all
- grails-crud
- grails-gorm
- grails-bootstrap
- grails-test
Check any other dependencies that may have shifted, especially hibernate, aspectj, javassist. This can be done by making a new grails project using the latest archetype and comparing with your current pom.
If you are lucky then mvn grails:exec -Dcommand=upgrade will now work
For me it didn’t, instead I got
C:\dev\svn\trunk>mvn grails:exec -Dcommand=upgrade
[INFO] Scanning for projects…
[INFO]————————————————————————
[INFO] Building SSE NG GUI
[INFO] task-segment: [grails:exec] (aggregator-style)
[INFO]————————————————————————
[INFO] [grails:exec {execution: default-cli}]
[INFO] Using Grails 1.3.4
Running pre-compiled script
Environment set to development
Clover: Using config: [on:false]WARNING: This target will upgrade an older Grails application to 1.3.4.
Are you sure you want to continue?
(y, n)
y
[delete] Deleting directory C:\dev\svn\trunk\web-app\WEB-INF\classes
[delete] Deleting: C:\dev\svn\trunk\target\resources\web.xml
[delete] Deleting directory C:\dev\svn\trunk\target\classes
[delete] Deleting directory C:\dev\svn\trunk\target\plugin-classes
[delete] Deleting directory C:\dev\svn\trunk\target\resources
[delete] Deleting directory C:\dev\svn\trunk\web-app\gwt
[INFO] ———————————————————————–\-
[ERROR] BUILD ERROR
[INFO] ———————————————————————–\-
[INFO] Unable to start GrailsEmbedded error: java.lang.reflect.InvocationTargetException
C:\dev\svn\trunk\null\src\war not found.
[INFO] ———————————————————————–\-
[INFO] For more information, run Maven with the -e switch
[INFO] ———————————————————————–\-
[INFO] Total time: 44 seconds
[INFO] Finished at: Wed Oct 20 09:03:02 BST 2010
[INFO] Final Memory: 37M/88M
[INFO] ———————————————————————–\-
Notice the \null\
This is an attempt to resolve GRAILS_HOME, failing as the maven plugin doesn’t use GRAILS_HOME.
A possible solution to this exists here http://tramuntanal.wikidot.com/upgrading-1-2
However this involves updating BuildConfig.groovy, to update dependency resolution. This option isn’t available to me, as we have disabled this functionality as it
duplicates the maven dependency resolution, causing some issues. I therefore did the following to complete the upgrade :-
- Update applicaiton.properties with the new grails version
- Obtain the latest hibernate plugin (from a grails installation) and install it
- Obtain the latest tomcat plugin (from a grails installation) and install it
The app then starts correctly.
I then tracked any bugs remaining in the app (probably post later on…)
Hi David,
Thanks for writing this post. I’m currently having problems upgrading to Grails 2.0.0 with Maven and I’m getting the same error from a null directory:
“Failed to execute goal org.grails:grails-maven-plugin:2.0.0.BUILD-SNAPSHOT:exec (default-cli) on project lincs_beta: Unable to start Grails: java.lang.reflect.InvocationTargetException: : /Users/jasonb/projects/cmap/null/src/war does not exist. -> [Help 1]”
How were you able to identify this as an attempt to find GRAILS_HOME ?
I haven’t solved the problem yet and I think that might be a good place to look.
Thanks,
Jason
Hi Jason.
As I remember, I dug into the grails scripts themselves. In an equivalent grails installation, sans maven, in the _war. gant script probably.
I don’t have the code in front of me today, I’ll have a look tomorrow along with my notes.
Hi David,
Thanks for getting back to me, I got a little further by going into the source for the Grails-Maven plugin and finding the Grails home var. I changed the value of System.getProperty string from “grailsHome” to “grails.home” to match my system var which allowed me to upgrade. But attempting to run the app gives me the same error:
Unable to start Grails: java.lang.reflect.InvocationTargetException: org.springframework.util.ReflectionUtils.isObjectMethod(Ljava/lang/reflect/Method;)Z
I’m going to dig into the Tomcat plugin today but please let me know if you do find any relevant notes.
Hmm.
I’ve not attempted the 2.0 upgrade yet, however the approach that I have used previously was to effectively do the upgrade manually (as above).
Update the application prop version, clean your grails working dir and then do any necessary fixes when running the app.
This bypasses the need for grails/ maven to do anything upgrade related.