Tame Your Gradle Dependencies just BECAUSE!

Did you know you can specify a reason for using a certain dependency or certain version of a dependency?

Yep it’s in the API here and referenced in the DOCS here.

void because?(@Nullable String reason)

Sets the reason why this dependency should be used.
Since:
4.6

Below is a basic example of how its used:

implementation("com.blundell:app-auth android:1.2.3") {
    because "We use fragment auth, original AppAuth library does not support this feature."
}

Gradle allows you to write a sentence or two of why you chose that dependency, and that comment can be picked up with this command, to be shown in a report:

gradle -q dependencyInsight –dependency app-auth android

But that’s not the interesting reason I see for using it!

A major benefit of using this feature is when working in a fast moving team. There is always some ryhme or reason why a certain dependency was used. Sometimes you stick on an earlier version for compatibility. Sometimes you use one parsing library over another because its compile time and not reflective. Sometimes you need to support multiple countries and this is the only dependency that’ll do it even though its not the industry standard goto.

All of these reasons usually get lost in the mists of time, if you are lucky they are in the git commit history message (but lets be honest, they won’t be the first thing checked).

Using the because function allows you to codify specific business decisions and make it explicit to the rest of your team why that decision was made. Saving time, effort and potential bugs with people wanting/looking/ignoring and changing dependencies.

So start using it! 🙂

implementation("com.blundell:android-blog:1.2.3") {
    because "If we didn't Blundell might cry."
}