Lookup version of transitive dependency


(Johannes Zillmann) #1

Hey there, quick question:

For larger projects (like Hadoop, Elasticsearch, Hibernate, etc…) i tend to disable transitive dependencies, e.g like that:
testCompile ('org.apache.hadoop:hadoop-common:'+ hadoopVersion) { transitive = false } testCompile ('org.apache.hadoop:hadoop-yarn-api:'+ hadoopVersion) { transitive = false } ...

and rather pick those transitive dependencies i really need explicitly:
testCompile ('commons-collections:commons-collections:3.2.1')

Why ? Because i don’t want to pollute my classpath with 30+ dependencies where in reality i need often only 4 to 10.
(different modules also have different needs, like API-only, tests, integration tests, etc… so its often different transitive dependency sets!)
I know i could also switch on transitives and set excludes, but i find explicit includes more convenient (i find it somehow easier to figure out what i need instead of figuring out what i don’t need).

The problem with that is that i need to figure out the versions of the transitive dependencies i include. In this example its ‘3.2.1’ of common-collections. That is nasty, esp. if the version of my main dependency is flexible. Say i can build my project by passing in the ‘hadoopVersion’.

So here is the question:
Is there some easy way to lookup the version of transitive dependency x from main dependency y ? (note that transitive is switched off for y)
Or am i’m missing some explicit includes mechanism for transitive dependencies ?

Any good advice appreciated! :wink:
Johannes