Skip to content

Minimum Dependency Version Rule

Jon Schneider edited this page Mar 7, 2017 · 6 revisions

The minimum dependency version rule makes the necessary changes to pull a project up to a minimum version of a dependency. If the project already meets or exceeds the target version, the rule does nothing.

To apply the rule, add:

gradleLint.rules += 'minimum-dependency-version'

To be effective, this rule requires an additional comma-delimited Gradle property gradleLint.minVersions to define which set of dependencies it is trying to pull up. This rule is generally most useful when ran as a one-off rule against a set of projects to pull them up to a minimum version:

./gradlew fixGradleLint -PgradleLint.rules=minimum-dependency-version -PgradleLint.minVersions=com.google.guava:guava:19.0

First-order dependencies not meeting the minimum requirements are updated:

dependencies {
   compile 'com.google.guava:guava:18.+' // upgraded to 19.0
}

When the dependency is only a transitive and does not meet the requirements, a first-order dependency is added:

dependencies {
   // depends on guava 18.0
   compile 'io.grpc:grpc-core:0.13.2' // new dependency on guava 19.0 is added
}

Interpolated values are replaced inline rather than where their variables are declared:

ext.GUAVA_VERSION = '18.0' // this value will NOT be changed

dependencies {
   compile "com.google.guava:guava:\$GUAVA_VERSION" // this is changed to 19.0
}

Forces preventing us from reaching the minimum version are updated:

configurations.compile {
   resolutionStrategy {
      force 'com.google.guava:guava:18.0' // updated to 19.0
   }
}

dependencies {
   // notice latest.release may be GREATER than 19.0, but 
   // we still update the force to the minimum version
   compile 'com.google.guava:guava:latest.release'
}