Running Griffon with an alternate Groovy version - No Fluff Just Stuff

Running Griffon with an alternate Groovy version

Posted by: Andres Almiray on March 21, 2011

A few people have asked the following question in the Griffon user mailing list

How can I run Griffon with a version of Groovy other than the bundled one?

There are several reasons to do so, here's one. Griffon has its own release cycle (as a matter of fact it just had a release earlier today) and as such it might not bundle the latest Groovy release (the latest stable one is 1.7.10 as a matter of fact) so what can you do if you want to test the bleeding edge (Groovy 1.8-rc2), say those nice new AST transformations like @Log, @Canonical and the like? Well, here's a quick way to do it. It is not as simple as replacing a jar file and flipping a switch but it's certainly doable.

Follow these steps to get the job done.
  1. Locate a suitable jar for the Groovy version you want to use, say 1.7.10. Download it and place it under $GRIFFON_HOME/lib.
  2. Delete the old Groovy version. In Griffon 0.9.2 it's $GRIFFON_HOME/lib/groovy-all-1.7.6.jar.
  3. Locate $GRIFFON_HOME/bin/startGroovy (startGroovy.bat if you're on Windows) and edit it. Search for the Groovy version you're exchanging (1.7.6 in this case) and change it to the target version you want.
    STARTER_CLASSPATH="$GRIFFON_HOME/lib/groovy-all-1.7.6.jar:$GRIFFON_HOME/dist/griffon-cli-0.9.2.jar:$GRIFFON_HOME/dist/griffon-rt-0.9.2.jar"

    changes to
    STARTER_CLASSPATH="$GRIFFON_HOME/lib/groovy-all-1.7.10.jar:$GRIFFON_HOME/dist/griffon-cli-0.9.2.jar:$GRIFFON_HOME/dist/griffon-rt-0.9.2.jar"

  4. Now comes the tricky part. Locate $GRIFFON_HOME/dist/griffon-cli-<version>.jar and unzip it to a directory of your choosing. We'll edit a properties file and repackage the jar
    $ cd /tmp
    $ unzip -dgriffon $GRIFFON_HOME/dist/griffon-cli-0.9.2.jar
    $ vim griffon/build.properties
    (edit 1.7.6 to 1.7.10; save the file)
    $ cd griffon
    $ jar cvf $GRIFFON_HOME/dist/griffon-cli-0.9.2.jar .

  5. The last and final step is clearing the Ivy cache if you have run Griffon before
    $ rm -rf $USER_HOME/.ivy2/cache/org.codehaus.griffon/griffon-cli
That should do it! Now Griffon will use Groovy 1.7.10 instead of the version it came with originally. It's worth mentioning that if the build.properties file is not changed and the cache is not reset then the old version will still be used. This trick will also work for exchanging the versions of the following dependencies: ant, slf4j and spring.

You might be wondering, why the complication? why not just replace a jar and be done with it? Well it turns out that Griffon has an internal DependencyManager that knows how to handle the set of bootstrap dependencies. This set is controller by the build.properties file we jus edited. Without those changes the default unchanged dependencies will be used. Now, what was that about applying @Canonical to Model classes? ;-)

Keep on Groovying!
Andres Almiray

About Andres Almiray

Andres is a Java/Groovy developer and a Java Champion with more than 20 years of experience in software design and development. He has been involved in web and desktop application development since the early days of Java. Andres is a true believer in open source and has participated on popular projects like Groovy, Griffon, and DbUnit, as well as starting his own projects (Json-lib, EZMorph, GraphicsBuilder, JideBuilder). Founding member of the Griffon framework and Hackergarten community event. https://ch.linkedin.com/in/aalmiray

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »