Exclude transitive dependency in Gradle

m_Z picture m_Z · Jan 30, 2017 · Viewed 12.6k times · Source

During build via Gradle I got this

POM relocation to an other version number is not fully supported in Gradle : xml-apis:xml-apis:2.0.2 relocated to xml-apis:x
ml-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.

Batik 1.7 was used in project. This version of Batik uses Xalan 2.6.0, which has dependency on xml-apis 2.0.2, which was relocated.

How to resolve this transitive dependency?

Answer

lance-java picture lance-java · Jan 30, 2017

Option 1:

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

See ResolutionStrategy.force(...)

Option 2:

dependencies {
    compile "batik:batik:$batikVersion", {
       exclude group: "xml-apis", module: "xml-apis"
    }
    compile "xml-apis:xml-apis:1.0.b2"
}

See ModuleDependency.exclude(Map)