26
Nov 09

Apache Ivy resolving local maven artifacts

Just submitted a fix to GRAILS-5327. This bug was really bothering me, mostly because ivy’s API documentation is non-existent. Even the user docs are begging to be enriched with more clarity and content.

Either way, for those of you facing the same issue. The problem is that sometimes you use maven to publish your modules to your local repository usually in ~/.m2/repository directory. Ivy has a FileSystemResolver which allows one to resolve to the file system using the maven2 patterns. It can be set up very easily, but the problem I ran into is that although ivy resolves the local dependencies, it does nothing about its transitive dependencies. WTF? Why would I even want to use ivy then. So I went looking, online through posting, bad documentation, and javadocs to no avail. There was one posting which specified that one should use the pom ending vs. [ext]. So my previous artifact pattern…

${repoPath}/[organisation]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]

should be changed to

${repoPath}/[organisation]/[module]/[revision]/[module]-[revision](-[classifier]).pom

I did this, but still not go. After trying a few combinations, I finally figured it out. Notice, the above artifact pattern is bolded. This is because ivy also has an ivy pattern. Because I’m not really interested in diving into ivy’s source (I seldom use it) and docs suck, I just took a dumb down brute force approach, let’s try a few combination and see how ivy behaves. Well, one of them worked. Basically, you must set both ivy and artifact patterns…

localFileSystemMavenResolver.addIvyPattern("${repoPath}/[organisation]/[module]/[revision]/[module]-[revision](-[classifier]).pom")
localFileSystemMavenResolver.addArtifactPattern("${repoPath}/[organisation]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]")

Why? I have no freaking idea. I’m not even going to guess, since even the posts by the core ivy team on the post linked above, seem to be stabbing in the dark. “try this…” they say. Well, it works. Maybe some day, I’ll have the interest and the time to look at ivy source, for now, I’m happy with using maven for most java projects and Grails’ new dependency management (using ivy for dep resolution) for my Grails projects.

Hope this helps anyone battling ivy. I would think a dependency resolution library that claims it can do for ant what maven does with dependency management, would at least properly and transitively resolve maven dependencies without too much poking around. I mean, are there any viable non-maven repositories out there? I really don’t think so.

Tags:

Leave a comment