0

When developing Hadoop applications very quickly many sub-modules of the main Hadoop project are required. In order to force a specific version, I as the author of my own Hadoop job would love to change the version of Hadoop for transitive libraries.

I.e. for all hadoop-* dependencies and transitive dependencies I want to set them to a version foo.bar.baz

How can I achieve this with Gradle without the need to manually specify each module?

Georg Heiler
  • 16,916
  • 36
  • 162
  • 292

2 Answers2

0

You'll want to write a custom dependency resolution rule. For example:

configurations.all {
    resolutionStrategy.eachDependency {
        if (requested.group == "org.apache.hadoop") {
            useVersion("3.2.1")
            because("some description why this version is needed.")
        }
    }
}

See https://docs.gradle.org/current/userguide/resolution_rules.html

An alternative to the above is to create/publish you're own custom platform or "BOM".

Cisco
  • 20,972
  • 5
  • 38
  • 60
  • Would it also be possible to put this into a different scope and apply this rule only to a specific dependency (and whatever it is pulling in transitively)? – Georg Heiler Apr 15 '20 at 05:09
0

If you are using Gradle 6+, I would strongly recommend looking into the dedicated chapter on dependency alignment and in particular the part about using virtual platforms. This combined with a strict version constraint should give you the result you need.

If you need to support a wider range of Gradle versions, the answer from Francisco Mateo with a resolution rule is a valid approach.

Louis Jacomet
  • 13,661
  • 2
  • 34
  • 43