views:

41

answers:

1

In my Gradle script (version 0.8), I have a local ivy repository which I use to publish a library, and I can't seem to get Gradle to ignore its cache.

I'm accessing the local ivy repo. based on the recommendation in the Gradle manual. Here's there relevant code (with some variables renamed).

dependencies{
  // [several remote dependencies]
  // ... 

  compile('myorg:mylib:0.1.0')
}

def ivy_repo = new org.apache.ivy.plugins.resolver.FileSystemResolver()
ivy_repo.name = 'ivy-repo'
ivy_repo.addIvyPattern local_repository + '/ivy/[organisation]/'+
   '[module]-ivy-[revision].xml'
ivy_repo.addArtifactPattern local_repository + '/ivy/[organisation]/'+
   '[module]-[revision](-[classifier]).[ext]'
ivy_repo.descriptor = 'optional'
ivy_repo.checkmodified = true

repositories{
  // [several remote repositories]
  // ...

  add(ivy_repo)
}

My problem is that when I run my script, once the local libraries are resolved, subsequent calls to the build script make use of the ~/.gradle/cache/myorg:mylib/, rather than the location of my local ivy repository. The Gradle manual has only a few lines mentioning that default local repositories should not use the cache, but I have found now way to actually indiciate that my repository is 'default' and local and thus shouldn't use the cache.

I've tried setting ivy_repo.local = true, or using compile('myorg:mylib:0.1.0'){changing = true}, but neither seems to work.

I don't want to use a flatDir repository because the local library has dependencies which I want my project to find (and I'm using the ivy file associated with the local library to do that now, and it appears that a flatDir repository ignores these sort of files... or maybe I was doing something wrong there?)

Anyone know a solution? Or maybe a better way to accomplish my task with Gradle?

A: 

Any ivy resolver has a Resolver.setRepositoryCacheManager() method. It takes a RepositoryCacheManager as an argument. You can create you own specially configured instance of DefaultRepositoryCacheManager and pass it to the method. With useOrigin you indicate that the cache shouldn't be used for artifacts.

DefaultRepositoryCacheManager cacheManager = new DefaultRepositoryCacheManager(); cacheManager.setName(name); cacheManager.setUseOrigin(true); cacheManager.setLockStrategy(new NoLockStrategy()); cacheManager.setIvyPattern(ResolverContainer.DEFAULT_CACHE_IVY_PATTERN);

We want to make this more convenient in 1.0.

Hans
Thanks! That seems to have done the trick. One small question: I noticed that although the proper classpath is now used, the libraries are still copied to the cache. What reason is there for the cache manager to copy over the files if useOrigin is set to 'true'?
David Little