so

POM relocation

Volume 2, Issue 29; 06 Dec 2018

Do you use Gradle for XML projects? Are you sick of the POM relocation warning for xml-apis? Me too!

Over the past several years, I’ve adopted Gradle as my go-to build tool That’s not strictly true; I’m learning to use sbt with my Scala projects. for any project that has a JVM component. There’s a simple reason why: Maven just works.

I’m not enamored of Groovy, really, but I’ve mostly reached the point where I can wrestle it into submission. I’ve written a couple of extensions that I find convenient, and there’s a really good extension for working with MarkLogic.

If you use Gradle for XML projects, the odds are good that you see this warning on every build:

POM relocation to an other version number is not fully supported in Gradle :
xml-apis:xml-apis:2.0.2 relocated to xml-apis:xml-apis:1.0.b2.
Please update your dependency to directly use the correct version
'xml-apis:xml-apis:1.0.b2'.
Resolution will only pick dependencies of the relocated element.
Artifacts and other metadata will be ignored.

You can ignore it, of course, but it irks me every time. I like my builds to be completely clean. Clean builds encourage good build hygiene and draw your attention to errors more quickly.

It’s doubly annoying because the xml-apis dependency isn’t one of mine. It’s a transitive dependency of some other package (which is probably in turn a transitive dependency of something else) way down the hierarchy from anything I’m using directly.

The underlying problem is, apparently, caused by the fact that the 2.0.2 version of xml-apis:xml-apis just points to version 1.0.b2 for its implementation and this “relocation” confuses Gradle. Frankly, it confuses me too, because there’s a 1.4.01 (sic) version of the APIs and I really don’t understand what’s going on with 2.0.2. But that’s a mystery for another day. (If anyone knows who’s responsible for xml-apis in Maven, I’d sure like to encourage them to sort out this versioning mess.)

The other day, I made a typo in my Gradle file and that sent me down a little web searching rabbit hole. Before I found my error and resurfaced, I stumbled across the following Gradle feature: you can declare various resolution strategies for dependencies. One of the strategies is force, as in:

configurations.all {
  resolutionStrategy {
    force 'xml-apis:xml-apis:1.4.01'
  }
}

Add that to your Gradle file to (1) tell Gradle to use the 1.4.01 version of xml-apis:xml-apis regardless of what’s in the dependency chain and (2) stop Gradle from giving that blasted relocation warning!

You’re welcome.

Please provide your name and email address. Your email address will not be displayed and I won’t spam you, I promise. Your name and a link to your web address, if you provide one, will be displayed.

Your name:

Your email:

Homepage:

Do you comprehend the words on this page? (Please demonstrate that you aren't a mindless, screen-scraping robot.)

What is four plus one?  (e.g. six plus two is 8)

Enter your comment in the box below. You may style your comment with the CommonMark flavor of Markdown.

All comments are moderated. I don’t promise to preserve all of your formatting and I reserve the right to remove comments for any reason.