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):

<ivysettings>
  <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" />
  <caches>
    <cache name="nocache" useOrigin="true" />
  </caches>
  <resolvers>
    <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>
      <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]"/>
      </filesystem>
      <!-- todo add 'endorsed groovy extensions' resolver here -->
      <ibiblio name="ibiblio" m2compatible="true"/>
      <ibiblio name="codehaus" root="http://repository.codehaus.org/" m2compatible="true"/>
      <ibiblio name="java.net2" root="http://download.java.net/maven/2/" m2compatible="true"/>
    </chain>
  </resolvers>
</ivysettings>

 

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.