I need to use a different Gradle plugin version dependening the Gradle version. How can I compare a version in Gradle? The variable gradle.gradleVersion is a string and can't good compare. The follow does not work if the minor version has only one digit.
buildscript {
dependencies {
def ver = gradle.gradleVersion >= '2.12' ? '+' : '1.5.+'
classpath group: 'de.inetsoftware', name: 'SetupBuilder', version: ver
}
}
To compare version numbers, compare their revisions in left-to-right order. Revisions are compared using their integer value ignoring any leading zeros. This means that revisions 1 and 001 are considered equal. If a version number does not specify a revision at an index, then treat the revision as 0 .
In Android Studio, go to File > Project Structure. Then select the "project" tab on the left. Your Gradle version will be displayed here.
You can add the --gradle-version X.Y argument to specify which version of Gradle to use. Now you can run any Gradle task in your project using the gradlew shell script or bat file located in your project's root directory.
Go to Android Studio -> Preferences -> Plugins (for Mac) and File -> Settings -> Plugins (for windows) and search “Check for Dependency updates plugin”. Install it and restart android studio. You will be able to see Dependencies tab on the right which will show if any dependency has a new update available.
The class VersionNumber is the trick:
buildscript {
dependencies {
def ver = VersionNumber.parse( gradle.gradleVersion ) >= VersionNumber.parse( '2.12' ) ? '+' : '1.5.+'
classpath group: 'de.inetsoftware', name: 'SetupBuilder', version: ver
}
}
Note: VersionNumber
is deprecated in Gradle 7 and is being removed from Gradle 8. There is no public replacement (it was never meant to be used outside of Gradle internal code). See docs.
https://docs.gradle.org/current/javadoc/org/gradle/util/VersionNumber.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With