Gradle Unused Dependencies



Gradle Unused Dependencies

Name Email Dev Id Roles Organization; Patrick Wendell: pwendellgmail.com: Databricks. If you do nothing, the dependency verification metadata will grow over time as you add new dependencies or change versions: Gradle will not automatically remove unused entries from this file. The reason is that there’s no way for Gradle to know upfront if a dependency will effectively be used during the build or not.

As you might know, by running $ ./gradlew dependencies gradle will print out the list of all libraries you are having at your build.gradle file and and all of their dependencies. You can find dependencies of a library easily if you are working on an small project however is not easy to find if you are working on an enterprise project or your project have different flavors. So the question is how to find (print out) dependencies of a particular dependency?

Gradle unused dependencies for selenium

Assume that we have following libraries in our build.gradle file. Although, it doesn't show any problem and you get it compiled successfully, there is a small problem. Second library, material date picker, has support library as its dependency and it's good practice to exclude it from build process since we already defined it. Also, if your project is very big you will get 65K method limitation during compile and it suggest you to active multidex build if you don't exclude duplicated dependencies. Multidex build activation adds extra complexity into the project and not all versions of Android are compatible with.

In order to find which dependencies must be excluded we must know a particular library is depends on what libraries. We can do it by adding a configuration to our build.gradle file like following snippet. You can add it at the end of build.gradle file.

Gradle Unused Dependencies Download

You can change the value of custom to whatever library you have in your main dependency and then run following command.

Gradle Unused Dependencies App

By doing this, gradle will print out dependencies of the library. So, you can remove it if the library has defined earlier for gradle. This is the output for our case:

Gradle Print Dependencies

So you can go back to your main dependency and exclude support library from build process.