- Gradle Unused Dependencies App
- Gradle Dependencies
- Gradle Pull Dependencies
- Gradle Unused Dependencies
- Gradle Unused Dependencies For Selenium
I wanted to find unused dependencies in my project. Is there any feature for this in gradle like in maven?
Answers:
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. Nov 11, 2019 Dependency hell is a big problem for many teams. The larger the project and its dependency graph, the harder it is to maintain it. The solutions provided by existing dependency management tools are insufficient to effectively deal with this issue. 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. This is a follow-up to The proper care and feeding of your Gradle build, in which I wrote about how to use the Dependency Analysis Gradle Plugin to help maintain a healthy build for your Android, Java, and Kotlin projects. In this first of a series of posts, we will discuss how that plugin works. 1 To begin, we will take a look at bytecode analysis with the ASM library, and how it is essential.
UPDATE: 28-06-2016: Android support to unused-dependency
On Square’s famous monolith, with nearly 3 000 Gradle modules (aka projects aka subprojects), buildHealth was invoked on a subsection of the full module graph, and there found about 3 000 unused dependencies (2 000 between modules and 1 000 external).
In June, 2017, they have released the
and renamed root project name
unused-dependency.
4.0.0 version
and renamed root project name
'gradle-lint-plugin'
to'nebula-lint-plugin'
. They have also added Android support tounused-dependency.
In May,2016 Gradle has implemented gradle lint plugin for finding and removing unwanted dependency
Gradle Lint Plugin: Full Documentation
Gradle Unused Dependencies App
The Gradle Lint plugin is a pluggable and configurable linter tool for
identifying and reporting on patterns of misuse or deprecations in
Gradle scripts and related files.
identifying and reporting on patterns of misuse or deprecations in
Gradle scripts and related files.
This plugin has various rules. Unused Dependency Rule is one of them. It has 3 specific characteristics.
- Removes unused dependencies.
- Promotes transitive dependencies that are used directly by your code
to explicit first order dependencies. - Relocates dependencies to the ‘correct’ configuration.
To apply the rule, add:
Details of Unused Dependency Rule is given in the last part.
To apply gradle lint plugin:
Alternatively:
Define which rules you would like to lint against:
For an enterprise build, we recommend defining the lint rules in a init.gradle script or in a gradle script that is included via the Gradle apply from mechanism.
For multimodule projects, we recommend applying the plugin in an allprojects block:
Details of Unused Dependency Rule is given in this part
To apply the rule, add:
The rule inspects compiled binaries emanating from your project’s source sets looking for class references, and matches those references to the dependencies that you have declared in your dependencies block.
Specifically, the rule makes the following adjustments to dependencies:
1) Removes unused dependencies
- Family-style jars like com.amazonaws:aws-java-sdk are removed, as
they contain no code
2) Promotes transitive dependencies that are used directly by your code to explicit first order dependencies
- This has the side effect of breaking up family style jars like
com.amazonaws:aws-java-sdk into the parts that you are actually
using, and adding those as first order dependencies
3) Relocates dependencies to the ‘correct’ configuration
- Webjars are moved to the runtime configuration
- Jars that contain no classes AND content outside of META-INF are
moved to runtime - ‘xerces’, ‘xercesImpl’, ‘xml-apis’ should always be runtime scoped
- Service providers (jars containing META-INF/services) like
mysql-connector-java are moved to runtime if there is no provable
compile-time reference - Dependencies are moved to the highest source set configuration
possible. For example, ‘junit’ is relocated to testCompile unless
there is an explicit dependency on it in the main source set (rare).
UPDATE: Previous plugins
For your kind information, I want to share about previous plugins
- Gradle plugin that finds unused dependencies, declared and transitive is com.github.nullstress.dependency-analysis
But it’s latest version 1.0.3 is created 23 December 2014. After that there is no update.
Gradle Dependencies
N.B: Many of our engineers are being confused about this plugin as they
updated only the version number nothing else.
updated only the version number nothing else.
Answers:
I’ve had a lot of luck using the Gradle Dependency Analysis Plugin. To get started with it, add the following two things to your Gradle build script.
and
Once those are in place, run
gradle analyze
. If there are unused dependencies, you’ll get a build failure that shows output similar to the text below, plus a list of the unused dependencies (both declared and transitive). The build failure is really handy if you want to enforce that there should be no unused dependencies via a CI build.Answers:
The project mentioned in the earlier answers seem to be dead. I use gradle-dependency-analyze. Setup is simple:
Then do:
Answers:
The projects on most of the historical answers are dead, but gradle-dependency-analyze appears to be alive at the time of this writing (last commit was two days ago).
Answers:
It’s not a built-in feature, and I’m not aware of a third-party plugin (but perhaps there is one).
Answers:
You can try com.github.nullstress.dependency-analysis gragle plugin
Build script snippet for use in all Gradle versions:
Build script snippet for new, incubating, plugin mechanism introduced in Gradle 2.1:
Also, there is a thread (Is there a Gradle equivalent of “mvn dependency:analyze”?) in gradle forum about this.
Tags: sed
- Status:Resolved
- Affects Version/s:0.9.1
Gradle Pull Dependencies
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.
Gradle Unused Dependencies
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:
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
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
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 Unused Dependencies For Selenium
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