Grape config for local maven repo

Here’s my new grape config that I’ve made to have proper support for local maven repository (UPD: fixed missing transitive dependencies – thanks to this StackOverflow question – ivy pattern should have POM extension):

  <settings defaultResolver="downloadGrapes"/>
  <property name="m2-pattern" value="${user.home}/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]" />
  <property name="m2-pattern-ivy" value="${user.home}/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision](-[classifier]).pom" />
    <cache name="nocache" useOrigin="true" />
    <chain name="downloadGrapes">
      <filesystem name="local-maven2" checkmodified="true" changingPattern=".*" changingMatcher="regexp" m2compatible="true" cache="nocache">
        <artifact pattern="${m2-pattern}"/>
        <ivy pattern="${m2-pattern-ivy}"/>
      <filesystem name="cachedGrapes">
        <ivy pattern="${user.home}/.groovy/grapes/[organisation]/[module]/ivy-[revision].xml"/>
        <artifact pattern="${user.home}/.groovy/grapes/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]"/>
      <!-- todo add 'endorsed groovy extensions' resolver here -->
      <ibiblio name="ibiblio" m2compatible="true"/>
      <ibiblio name="codehaus" root="" m2compatible="true"/>
      <ibiblio name="java.net2" root="" m2compatible="true"/>


Previously I’ve had local maven repo declared this way:

<ibiblio name="local" root="file:${user.home}/.m2/repository/" m2compatible="true"/>

This introduced two issues: I did not have latest versions of SNAPSHOT libraries due to caching made by grape, and I had two copies of same libraries on my machine for the same reason – one in grape cache and one in local maven repo.

No combination of checkmodified, changingPattern and/or changingMatcher solved this – the repo was considered remote and thus subject to caching by default cache.

So two things were made here – the repo was declared via filesystem in order to indicate that it’s a local repo, and “nocache” cache with useOrigin=”true” was specifically set for it, making grape only keep grape config xmls in cache, but not copy actual JARs, and always get latest versions as they are in .m2 folder.

Now some credit to the author – the fix was found in this StackOverlow question, asked and auto-answered by Jean-Philippe Pellet. Thanks mr.Pellet!

P.S. If something doesn’t get resolved – don’t panick, just try removing it from ivy cache first and then re-grab.