Skip to content

Unused Exclude Rule

Jon Schneider edited this page May 11, 2016 · 1 revision

Two rules are provided to deal with managing exclude hygiene. Developers often introduce excludes as a temporary measure to get past a dependency issue. As time passes and new versions of dependencies are released and incorporated into the build, these excludes may no longer have any effect on the dependency graph. Unfortunately, developers are generally unaware of when excludes no longer have an effect, and so they remain in the build, adding cognitive load with no benefit.

Unused dependency excludes

To apply the rule, add:

gradleLint.rules += 'unused-exclude-by-dep'

This rule weeds out dependency-level excludes that no longer have an effect on the dependency graph:

dependencies {
  compile('commons-configuration:commons-configuration:1.10') {
      exclude group: 'com.google.guava', module: 'guava'
  }
}

In this example, commons-configuration does not depend on guava, so the exclude has no effect and will be struck by the rule.

Unused configuration excludes

To apply the rule, add:

gradleLint.rules += 'unused-exclude-by-conf'

This rule weeds out configuration-level excludes that no longer have an effect on the dependency graph:

configurations {
    all*.exclude group: 'com.google.guava', module: 'guava'
}

dependencies {
  compile 'commons-configuration:commons-configuration:1.10'
}

In this example, we have no first order or transitive dependencies on guava, so the exclude has no effect and will be struck by the rule.