I wanted to find unused dependencies in my project. Is there any feature for this in gradle like in maven?

  1. Gradle Compile Exclude
  2. Gradle Exclude Jar Dependencies
  3. Gradle Configurations Exclude

Dec 19, 2017 gradleLint.rules += 'unused-dependency' The rule inspects compiled binaries emanating from your project’s source setslooking for class references, and matches those references to the dependencies that you have declared in your dependenciesblock. Specifically, the rule makes the following adjustments to dependencies. It’s worth mentioning that while Gradle can generate a dependency verification file for you, you should always check whatever Gradle generated for you because your build may already contain compromised dependencies without you knowing about it. The preceding example shows three key concepts to Gradle dependency management: configurations (compile), dependencies (org.springframework:spring-core:3.0.5), and repositories (mavenCentral). A “configuration” is a named grouping of dependencies. A Gradle build can have zero or more of them. A “repository” is a source of dependencies. Some dependencies are located in different repositories, so before you try to add one make sure that it can be located in one of the repository you have listed. If it isn’t, read up on how to use other external repositories in Gradle’s documentation. Using dependencies. By themselves, dependencies are useless and just a bunch of weight. 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.

Answers:

UPDATE: 28-06-2016: Android support to unused-dependency

In June, 2017, they have released the 4.0.0 version
and renamed root project name 'gradle-lint-plugin' to
'nebula-lint-plugin'. They have also added Android support to
unused-dependency
.

In May,2016 Gradle has implemented gradle lint plugin for finding and removing unwanted dependency

Gradle Lint Plugin: Full Documentation

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.

This plugin has various rules. Unused Dependency Rule is one of them. It has 3 specific characteristics.

  1. Removes unused dependencies.
  2. Promotes transitive dependencies that are used directly by your code
    to explicit first order dependencies.
  3. 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:

Gradle check unused dependencies failed

Alternatively:

Define which rules you would like to lint against: Soundtoys 5 osx torrent.

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:

Gradle Compile Exclude

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 Check Unused Dependencies
  1. Gradle plugin that finds unused dependencies, declared and transitive is com.github.nullstress.dependency-analysis

Gradle Exclude Jar Dependencies

But it’s latest version 1.0.3 is created 23 December 2014. After that there is no update.

N.B: Many of our engineers are being confused about this plugin as they
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

Gradle Configurations Exclude

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: Numark dj2go virtual dj 8.

Also, there is a thread (Is there a Gradle equivalent of “mvn dependency:analyze”?) in gradle forum about this.

Gradle Check Unused Dependencies

Tags: sed