Skip to content

Duplicate Classes Rule

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

The unused dependency rule is an example of a simple dependency hygiene rule.

To apply the rule, add:

gradleLint.rules += 'duplicate-dependency-class'

The rule examines the map of classes to jars coming from both direct and transitive dependencies. When a class is defined by more than one jar, your application is at risk of breakage if the order of classpath entries changes. This type of breakage can be particularly difficult for developers to track down, because often the jar containing a duplicate class comes in transitively, and the order of classpath entries may be different in a local environment or IDE than it is in a deployed environment making the problem difficult to reproduce.

Generally, duplicate classes on the classpath are a result of package relocations, for example:

  • com.google.collections:google-collections -> com.google.guava:guava
  • javassist:javassist -> org.javassist:javassist
  • asm:asm -> org.ow2.asm:asm
  • bouncycastle:bcprov-jdk12, bouncycastle:bcprov-jdk13, bouncycastle:bcprov-jdk14, etc.

Unfortunately, Gradle conflict resolution will not help us with these, although nebula.resolution-rules provides some relief.