Search

Dark theme | Light theme

August 25, 2010

Groovy Goodness: Resolve Module Location with Grape

Grape in Groovy is a great way to define dependencies in our scripts and let Groovy download them automatically for us. We also can use the command-line tool grape to resolve the location of modules on our system. We use the resolve command to get the absolute path to our dependency, but we can even pass extra arguments like -shell and -dos and we get the location as a CLASSPATH environment variable. If we use -ant we can use the output in a ANT build file. Or -ivy to get the information in Ivy XML format.

$ grape resolve commons-lang commons-lang 2.5
/Users/mrhaki/.groovy/grapes/commons-lang/commons-lang/jars/commons-lang-2.5.jar

$ grape resolve -dos commons-lang commons-lang 2.5
set CLASSPATH=/Users/mrhaki/.groovy/grapes/commons-lang/commons-lang/jars/commons-lang-2.5.jar

$ grape resolve -shell commons-lang commons-lang 2.5
export CLASSPATH=/Users/mrhaki/.groovy/grapes/commons-lang/commons-lang/jars/commons-lang-2.5.jar

$ grape resolve -ant commons-lang commons-lang 2.5
<pathelement location="/Users/mrhaki/.groovy/grapes/commons-lang/commons-lang/jars/commons-lang-2.5.jar">

$ grape resolve -ivy commons-lang commons-lang 2.5
<dependency org="commons-lang" name="commons-lang" revision="2.4">