I have a project child with build.gradle as follows.
dependencies{
compile 'com.google.guava:guava:17'
}
I've another project called parent with build.gradle as follows.
dependencies{
compile project(':child')
compile 'com.google.guava:guava:23'
}
Now my question is which version will child project use at runtime? I know Gradle dependency tree shows 17 -> 23
. But does that mean child will also use a newer version of guava? What if I wanted to use guava:23
in parent but it has some class missing that child uses?
What if I don't control child and it's included as an external dependency in parent like:
compile 'xxx:child:1.0'
Does that mean I'll never be able to upgrade my guava version until child does?
In Java, you can have at most one version of a library on the classpath (or, at least, everything else causes trouble...).
So if your "parent" uses "child" and they both use guava, you need to find a version of guava that fits for both of them.
Usually, Gradle uses the newest version of a dependency if it finds several versions on the dependency tree. You can certainly get more fine grained control, but haven't used Gradle in a long time (only Maven, where your direct dependency always wins, and other conflicts are sorted out with dependencyManagement).