(Quick Reference)

3.5 Dependency Resolution - Reference Documentation

Authors: Andres Almiray

Version: 1.2.0

3.5 Dependency Resolution

In order to control how JAR dependencies are resolved Griffon features (since version 0.9) a dependency resolution DSL that allows you to control how dependencies for applications and plugins are resolved.

Inside the griffon-app/conf/BuildConfig.groovy file you can specify a griffon.project.dependency.resolution property that configures how dependencies are resolved:

griffon.project.dependency.resolution = {
   // config here
}

The default configuration looks like the following:

griffon.project.dependency.resolution = {
    // inherit Griffon' default dependencies
    inherits("global") {
    }
    log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
    repositories {
        griffonHome()

// uncomment the below to enable remote dependency resolution // from public Maven repositories //mavenLocal() //mavenCentral() //mavenRepo "http://snapshots.repository.codehaus.org" //mavenRepo "http://repository.codehaus.org" //mavenRepo "http://download.java.net/maven/2/" //mavenRepo "http://repository.jboss.com/maven2/" } dependencies { // specify dependencies here under either 'build', 'compile', 'runtime' or 'test' scopes eg. // runtime 'mysql:mysql-connector-java:5.1.5' } }

The details of the above will be explained in the next few sections.

3.5.1 Configurations and Dependencies

Griffon features 5 dependency resolution configurations (or 'scopes') which you can take advantage of:
  • build: Dependencies for the build system only
  • compile: Dependencies for the compile step
  • runtime: Dependencies needed at runtime but not for compilation (see above)
  • test: Dependencies needed for testing but not at runtime (see above)

Within the dependencies block you can specify a dependency that falls into one of these configurations by calling the equivalent method. For example if your application requires the MySQL driver to function at runtime you can specify as such:

runtime 'com.mysql:mysql-connector-java:5.1.5'

The above uses the string syntax which is group:name:version. You can also use a map-based syntax:

runtime group:'com.mysql', name:'mysql-connector-java', version:'5.1.5'

Multiple dependencies can be specified by passing multiple arguments:

runtime 'com.mysql:mysql-connector-java:5.1.5',
        'commons-lang:commons-lang:2.6'

// Or

runtime( [group: 'com.mysql', name: 'mysql-connector-java', version: '5.1.5'], [group: 'commnons-lang', name: 'commons-lang', version: '2.6'] )

You may specify a classifier too

runtime 'net.sf.json-lib:json-lib:2.4:jdk15'

// Or

runtime group: 'net.sf.json-lib' name: 'json-lib', version: '2.4', classifier: 'jdk15'

3.5.2 Dependency Repositories

Remote Repositories

Griffon, when installed, does not use any remote public repositories. There is a default griffonHome() repository that will locate the JAR files Griffon needs from your Griffon installation. If you want to take advantage of a public repository you need to specify as such inside the repositories block:

repositories {
    mavenCentral()
}

In this case the default public Maven repository is specified. To use the SpringSource Enterprise Bundle Repository you can use the ebr() method:

repositories {
    ebr()
}

You can also specify a specific Maven repository to use by URL:

repositories {
    mavenRepo "http://repository.codehaus.org"
}

Local Resolvers

If you do not wish to use a public Maven repository you can specify a flat file repository:

repositories {
    flatDir name:'myRepo', dirs:'/path/to/repo'
}

Custom Resolvers

If all else fails since Griffon builds on Apache Ivy you can specify an Ivy resolver:

repositories {
    resolver new URLResolver(...)
}

Authentication

If your repository requires some form of authentication you can specify as such using a credentials block:

credentials {
    realm = ".."
    host = "localhost"
    username = "myuser"
    password = "mypass"
}

The above can also be placed in your USER_HOME/.griffon/settings.groovy file using the griffon.project.ivy.authentication setting:

griffon.project.ivy.authentication = {
    credentials {
        realm = ".."
        host = "localhost"
        username = "myuser"
        password = "mypass"
    }    
}

3.5.3 Debugging Resolution

If you are having trouble getting a dependency to resolve you can enable more verbose debugging from the underlying engine using the log method:

// log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
log "warn"

3.5.4 Inherited Dependencies

By default every Griffon application inherits a bunch of framework dependencies. This is done through the line:

inherits "global"

Inside the BuildConfig.groovy file. If you wish exclude certain inherited dependencies then you can do so using the excludes method:

inherits("global") {
    excludes "oscache", "ehcache"
}

3.5.5 Dependency Reports

As mentioned in the previous section a Griffon application consists of dependencies inherited from the framework, the plugins installed and the application dependencies itself.

To obtain a report of an application's dependencies you can run the dependency-report command:

griffon dependency-report

This will output a report to the target/dependency-report directory by default. You can specify which configuration (scope) you want a report for by passing an argument containing the configuration name:

griffon dependency-report runtime

3.5.6 Plugin JAR Dependencies

The way in which you specify dependencies for a plugin is identical to how you specify dependencies in an application. When a plugin is installed into an application the application automatically inherits the dependencies of the plugin.

If you want to define a dependency that is resolved for use with the plugin but not exported to the application then you can set the exported property of the dependency:

compile('org.hibernate:hibernate-core:3.3.1.GA') {
    exported = false
}

In this can the hibernate-core dependency will be available only to the plugin and not resolved as an application dependency.