James
James

Reputation: 3555

Gradle dependency library updated by another library

My gradle has for some time had a dependency on the (amazing) Android library Picasso. It has always been set to version 2.5.2

implementation 'com.squareup.picasso:picasso:2.5.2'

I recently updated all my Firebase libraries from a fairly old version to the latest. At which point something odd happened.

My Picasso method calls began to error

Picasso.with(context)

Which I know from this SO article results from a change to Picasso. cannot find symbol method with() using picasso library android and I need to change to

Picasso.get()

OK not a big deal, but it got me wondering. Obviously Firebase uses the latest version of Picasso and is making my project use the latest version as well. My question is why is my local gradle file ignored and the newer version of Picasso defaulted to?

Upvotes: 1

Views: 441

Answers (2)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363825

You can check the official doc:

Gradle resolves version conflicts by picking the highest version of a module. Build scans and the dependency insight report are immensely helpful in identifying why a specific version was selected.

Upvotes: 1

Koenigsberg
Koenigsberg

Reputation: 1798

Off the top of my head: Since you declare a specific version that requirement is not flexible. To allow for a newer version if available a + declaration is required. My guess is that another dependency is also dependent on Picasso after the updates. Gradle, when given a redundant dependency, will select the newer version.

This is in alignment with what you said, if I understand correctly. If Firebase uses a newer Picasso version, because it requires that version, then Gradle is given two versions to choose one from. This will always result in the newer version being chosen. At least this is default behavior afaik.

It seems to me that you already know Picasso is used by Firebase. If you want to see where which dependency comes from however, you can look into build scans:

gradle build --scan

https://scans.gradle.com/?_ga=2.166196030.1236003146.1565212874-222812074.1565212874

A little bit more advanced dependency management:

1) Set Gradle behavior on dependency conflict:

https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html

2) Declare version constraints (see Rich version declaration):

https://docs.gradle.org/current/userguide/declaring_dependencies.html

Upvotes: 1

Related Questions