Groovy - Grape Dependency Manager

About

Grape is a Dependency manager based on Ivy.

Syntax

You add dependencies in the script as an annotation.

  • Basic Notation
// Long notation
@Grab(group='com.gerardnico', module='niofs-sftp', version='1.0.0')
// Shorthand Notation
@Grab('com.gerardnico:niofs-sftp:1.0.0') 
  • Grapes Notation
@Grapes([
    @Grab(group='com.jcraft', module='jsch', version='0.1.53'),
    @Grab(group='com.gerardnico', module='niofs-sftp', version='1.0.0')
])

The Maven Repository gives you the Grab notation.

Example: http://mvnrepository.com/artifact/com.jcraft/jsch/0.1.53

Management

Installation of Artifact in the Grape repo

Grape will lookup different maven repositories in order to find it.

The repositories are configured in a Ivy settings file located ~/.groovy/grapeConfig.xml

grape install "com.gerardnico" "niofs-sftp" "1.0.0"
:: loading settings :: url = jar:file:/C:/groovy-2.4.5/bin/../lib/ivy-2.4.0.jar!/org/apache/ivy/core
/settings/ivysettings.xml
:: resolving dependencies :: caller#all-caller;working47
        confs: [default]
        found com.gerardnico#niofs-sftp;1.0.0 in localm2
        found com.jcraft#jsch;0.1.51 in localm2
downloading file:C:/Users/gerard/.m2/repository/com/gerardnico/niofs-sftp/1.0.0/niofs-sftp-1.0.0.jar
 ...
        [SUCCESSFUL ] com.gerardnico#niofs-sftp;1.0.0!niofs-sftp.jar (31ms)
downloading file:C:/Users/gerard/.m2/repository/com/jcraft/jsch/0.1.51/jsch-0.1.51.jar ...
        [SUCCESSFUL ] com.jcraft#jsch;0.1.51!jsch.jar (94ms)

List

grape list
com.jcraft jsch  [0.1.51, 0.1.53]
org.sonatype.oss oss-parent  [6]

2 Grape modules cached
3 Grape module versions cached

Configuration

Repository Directory

If you need to change the directory grape uses for downloading libraries you can specify the grape.root system property to change the default (which is ~/.groovy/grape)

groovy -Dgrape.root=/repo/grape yourscript.groovy

Documentation / Reference


Powered by ComboStrap