Gradle Unused Dependencies



  • Status:Resolved
  • Affects Version/s:0.9.1

Every dependency declared for a Gradle project applies to a specific scope. For example some dependencies should be used for compiling source code whereas others only need to be available at runtime. Gradle represents the scope of a dependency with the help of a Configuration. Every configuration can be identified by a unique name. Oct 23, 2020 Declaring dependencies. To add a dependency on Room, you must add the Google Maven repository to your project. Read Google's Maven repository for more information. Dependencies for Room include testing Room migrations and Room RxJava. Add the dependencies for the artifacts you need in the build.gradle file for your app or module. Name Email Dev Id Roles Organization; Patrick Wendell: pwendellgmail.com: Databricks.

I have a project with a large number of dependencies in the build file. The dependencies have been configured to come from a local installation of Nexus, which will then proxy various external repos as well as our own hosted repositories.

Often, when running a simple task (or just calling 'gradle depenencies'), gradle will pause for a very long time (often up to 5 minutes) while it displays messages about retrieving various pom files for other internal projects. It seemed an unusually long time to pause, so I started wireshark to see what was happening: it appears that for every jar file we depend on, gradle will also do a HTTP HEAD request on various associated artifacts. For example, to retrieve a
jar called DataType, the following requests are made:

HEAD /nexus/content/groups/public/com/example/DataType/1.0.94/DataType-1.0.94.pom HTTP/1.1
GET /nexus/content/groups/public/com/example/DataType/1.0.94/DataType-1.0.94.pom HTTP/1.1
HEAD /nexus/content/groups/public/com/example/DataType/1.0.94/DataType-1.0.94.jar HTTP/1.1
HEAD /nexus/content/groups/public/com/example/DataType/1.0.94/DataType-1.0.94-sources.jar HTTP/1.1
HEAD /nexus/content/groups/public/com/example/DataType/1.0.94/DataType-1.0.94-src.jar HTTP/1.1
HEAD /nexus/content/groups/public/com/example/DataType/1.0.94/DataType-1.0.94-javadoc.jar HTTP/1.1
GET /nexus/content/groups/public/com/example/DataType/1.0.94/DataType-1.0.94.jar HTTP/1.1

Gradle see dependencies

The problem is that DataType-1.0.94-sources.jar, DataType-1.0.94-src.jar and DataType-1.0.94-javadoc.jar do not exist. Because gradle requested them, Nexus realises that it doesn't have them locally, and then searches the external repositories for them, which takes a long time (sometimes up to 10 seconds). Multiple this by about 20 different dependencies, this adds an enormous amount of time to what I would have expected to be a quick task.

Gradle should not be requesting the '-sources', '-src' and '-javadoc' artifacts when it doesn't need them.

Votes:
2Vote for this issue
Watchers:
3Start watching this issue
  • Status:Resolved
  • Affects Version/s:None
Dependencies

Gradle Pull Dependencies

Maven metadata allows for 'optional' dependencies, which is quite important for frameworks like Spring, where we must compile against certain artifacts, but use by end users is optional (i.e. if they don't use particular classes, they don't need the dependency).

Ivy allows for expressing this, Maven allows for expressing this.

What we need is something like:

And for that to be reflected in the generated pom.xml as:

Gradle Lint Unused Dependencies

See also: http://gradle.1045684.n5.nabble.com/Marking-Maven-Dependencies-as-optional-td1432582.html

Gradle Unneeded Dependencies

Votes:
57Vote for this issue
Watchers:
54Start watching this issue