Monday, November 15, 2010

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]")

libResolver.name = "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 {
grailsPlugins()
grailsHome()
grailsCentral()

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'
}
}

3 comments:

Chochos said...

This was useful indeed, although I'm still trying to figure out how to solve a similar problem. I have many Eclipse projects with the classic src and bin directories; I would like to have a resolver that can add to the classpath the bin directory of a project I specify.

Similar to what you have, except that instead of finding "artifact.jar" it would add the "artifact/bin" directory to the classpath. Maybe I need to write my own resolver.

Nick said...

Hmm... not sure if the Ivy repository resolver can support folder based artifact. Is it possible for you to package the classes into a jar before adding them to the classpath?

Aaron said...

My question is how do you have to structure the repository so that grails can find the plugins?