Dmytro D
Dmytro D

Reputation: 2584

How does gradle resolve duplicate dependencies with different versions like Retrofit?

Suppose, I want to create android library with Retrofit 2.0.0 dependency. What if developer, that will use my library also would have dependency with Retrofit lower version (i.e. 1.9.0) in his project , how gradle will resolve this ? Also, Is it bad approach to use libraries like Retrofit in my own library to simplify code?

Upvotes: 3

Views: 825

Answers (1)

Stanislav
Stanislav

Reputation: 28096

Gradle has a number of dependency resolution strategies, you can take a look at the dependency management part of the official Gradle user guide. Especially at 52.2.3. Resolve version conflicts.

The most common strategies are Newest:

Newest: The newest version of the dependency is used. This is Gradle's default strategy, and is often an appropriate choice as long as versions are backwards-compatible.

And Fail:

Fail: A version conflict results in a build failure. This strategy requires all version conflicts to be resolved explicitly in the build script. See ResolutionStrategy for details on how to explicitly choose a particular version.

So, the behaviour of dependency resolution in gradle build script depend on what resolution strategy is used. In most cases, the newer version will be used.

The questions like "Is it bad approach to use libraries like Retrofit in my own library to simplify code?" are mostly opinion based, as for me. You are able to use anything you need, especially if you can't do something without it or it'll take too long to implement it yourself. Tools like a Gradle are made to simplify your life and try to solve most of the problems you can catch with transitive dependencies and you don't have to worry much about it. If you are not creating some widely used library, which should run everywhere no doubt.

Upvotes: 3

Related Questions