Monday, November 15

Use Flat Local Folder as Custom Repository for Grails

Currently I am introducing Grails as one of the new web application frameworks to my client in their existing environment, however their environment currently does not rely on Maven or Ivy repository manager to distribute and share their internal libraries but rather checked into version control under one directory flat. To make Grails recognize this flat file folder as one of the dependency repository, we had to configure the BuildConfig script with a custom Ivy resolver. I thought someone else might find its useful if you are dealing with legacy build environment.

// create a custom file based resolver
def libResolver = new org.apache.ivy.plugins.resolver.FileSystemResolver()

// specify common lib directory
def commonLibDir = new File("c:\commonLib")

// specify patterns
libResolver.addArtifactPattern(commonLibDir + "/[artifact]")
libResolver.addIvyPattern(commonLibDir + "/[artifact]") = "my-repository"

grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// uncomment to disable ehcache
// excludes 'ehcache'
log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
repositories {

resolver libResolver
dependencies {
// here the groupid and version are basically ignored since our
// flat lib folder does not maintain such information
compile 'yourcompany:artifact.jar:0.0.0'