build.gradle, settings.gradle: simplify Gradle version comparisons

This commit is contained in:
Andrey 2024-09-25 19:58:52 +03:00 committed by Andreas Schildbach
parent 20b739c578
commit e0c20f2bb0
6 changed files with 13 additions and 13 deletions

View File

@ -39,7 +39,7 @@ test {
def gradleVersionToolchains = GradleVersion.version("6.7") def gradleVersionToolchains = GradleVersion.version("6.7")
if (GradleVersion.current().compareTo(gradleVersionToolchains) > 0) { if (GradleVersion.current() > gradleVersionToolchains) {
// If the Gradle Java Toolchains feature is available, run tests on older JDKs // If the Gradle Java Toolchains feature is available, run tests on older JDKs
System.err.println "Adding 'testOnJdk8' task, because ${GradleVersion.current()}" System.err.println "Adding 'testOnJdk8' task, because ${GradleVersion.current()}"
@ -69,7 +69,7 @@ jar {
def minGradleArchiveClassifierVersion = GradleVersion.version("5.0") def minGradleArchiveClassifierVersion = GradleVersion.version("5.0")
task javadocJar(type: Jar, dependsOn: javadoc) { task javadocJar(type: Jar, dependsOn: javadoc) {
if (GradleVersion.current().compareTo(minGradleArchiveClassifierVersion) > 0) { if (GradleVersion.current() > minGradleArchiveClassifierVersion) {
archiveClassifier.set('javadoc') archiveClassifier.set('javadoc')
} else { } else {
classifier = 'javadoc' classifier = 'javadoc'
@ -78,7 +78,7 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
} }
task sourcesJar(type: Jar, dependsOn: classes) { task sourcesJar(type: Jar, dependsOn: classes) {
if (GradleVersion.current().compareTo(minGradleArchiveClassifierVersion) > 0) { if (GradleVersion.current() > minGradleArchiveClassifierVersion) {
archiveClassifier.set('sources') archiveClassifier.set('sources')
} else { } else {
classifier = 'sources' classifier = 'sources'

View File

@ -5,7 +5,7 @@ buildscript {
mavenCentral() mavenCentral()
} }
// If using Gradle 7, use the compatible protobuf plugin, else use the one that works with oldest supported Gradle // If using Gradle 7, use the compatible protobuf plugin, else use the one that works with oldest supported Gradle
boolean isGradle7 = GradleVersion.current().compareTo(GradleVersion.version("7.0")) >= 0 boolean isGradle7 = GradleVersion.current() >= GradleVersion.version("7.0")
def gradleProtobufVersion = isGradle7 ? "0.9.4" : "0.8.10" def gradleProtobufVersion = isGradle7 ? "0.9.4" : "0.8.10"
if (isGradle7) { if (isGradle7) {
System.err.println "Warning: Using com.google.protobuf:protobuf-gradle-plugin:${gradleProtobufVersion} because ${GradleVersion.current()}" System.err.println "Warning: Using com.google.protobuf:protobuf-gradle-plugin:${gradleProtobufVersion} because ${GradleVersion.current()}"

View File

@ -28,7 +28,7 @@ dependencies {
// Prevent newer Gradle from switching to JRE version of Guava // Prevent newer Gradle from switching to JRE version of Guava
def gradleVersionTargetJVM = GradleVersion.version("7.0") def gradleVersionTargetJVM = GradleVersion.version("7.0")
if (GradleVersion.current().compareTo(gradleVersionTargetJVM) > 0) { if (GradleVersion.current() > gradleVersionTargetJVM) {
dependencies.constraints { dependencies.constraints {
implementation("com.google.guava:guava") { implementation("com.google.guava:guava") {
attributes { attributes {
@ -82,7 +82,7 @@ test {
def gradleVersionToolchains = GradleVersion.version("6.7") def gradleVersionToolchains = GradleVersion.version("6.7")
if (GradleVersion.current().compareTo(gradleVersionToolchains) > 0) { if (GradleVersion.current() > gradleVersionToolchains) {
// If the Gradle Java Toolchains feature is available, run tests on older JDKs // If the Gradle Java Toolchains feature is available, run tests on older JDKs
System.err.println "Adding 'testOnJdk8' task, because ${GradleVersion.current()}" System.err.println "Adding 'testOnJdk8' task, because ${GradleVersion.current()}"
@ -112,7 +112,7 @@ jar {
def minGradleArchiveClassifierVersion = GradleVersion.version("5.0") def minGradleArchiveClassifierVersion = GradleVersion.version("5.0")
task javadocJar(type: Jar, dependsOn: javadoc) { task javadocJar(type: Jar, dependsOn: javadoc) {
if (GradleVersion.current().compareTo(minGradleArchiveClassifierVersion) > 0) { if (GradleVersion.current() > minGradleArchiveClassifierVersion) {
archiveClassifier.set('javadoc') archiveClassifier.set('javadoc')
} else { } else {
classifier = 'javadoc' classifier = 'javadoc'
@ -121,7 +121,7 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
} }
task sourcesJar(type: Jar, dependsOn: classes) { task sourcesJar(type: Jar, dependsOn: classes) {
if (GradleVersion.current().compareTo(minGradleArchiveClassifierVersion) > 0) { if (GradleVersion.current() > minGradleArchiveClassifierVersion) {
archiveClassifier.set('sources') archiveClassifier.set('sources')
} else { } else {
classifier = 'sources' classifier = 'sources'

View File

@ -8,7 +8,7 @@ import org.gradle.util.GradleVersion
// required Gradle version for build // required Gradle version for build
def gradleVersion = GradleVersion.version("4.4.1") def gradleVersion = GradleVersion.version("4.4.1")
if (GradleVersion.current().compareTo(gradleVersion) != 0) { if (GradleVersion.current() != gradleVersion) {
throw new GradleScriptException("bitcoinj build requires Debian Gradle ${gradleVersion.version}", null) throw new GradleScriptException("bitcoinj build requires Debian Gradle ${gradleVersion.version}", null)
} }

View File

@ -10,7 +10,7 @@ def minGradleVersion = GradleVersion.version("7.3")
rootProject.name = 'bitcoinj-parent' rootProject.name = 'bitcoinj-parent'
if (GradleVersion.current().compareTo(minGradleVersion) < 0) { if (GradleVersion.current() < minGradleVersion) {
throw new GradleScriptException("bitcoinj build requires Gradle ${minGradleVersion.version} or later", null) throw new GradleScriptException("bitcoinj build requires Gradle ${minGradleVersion.version} or later", null)
} }
if (!JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) { if (!JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) {

View File

@ -8,12 +8,12 @@ plugins {
} }
def annotationProcessorMinVersion = GradleVersion.version("4.6") def annotationProcessorMinVersion = GradleVersion.version("4.6")
boolean hasAnnotationProcessor = (GradleVersion.current().compareTo(annotationProcessorMinVersion) >= 0) boolean hasAnnotationProcessor = GradleVersion.current() >= annotationProcessorMinVersion
def junit5MinVersion = GradleVersion.version("4.6") def junit5MinVersion = GradleVersion.version("4.6")
boolean hasJunit5 = (GradleVersion.current().compareTo(junit5MinVersion) >= 0) boolean hasJunit5 = GradleVersion.current() >= junit5MinVersion
def graalVMMinVersion = GradleVersion.version("7.4") // Toolchains with selection by vendor def graalVMMinVersion = GradleVersion.version("7.4") // Toolchains with selection by vendor
boolean hasGraalVM = (GradleVersion.current().compareTo(graalVMMinVersion) >= 0) boolean hasGraalVM = GradleVersion.current() >= graalVMMinVersion
dependencies { dependencies {
implementation project(':bitcoinj-core') implementation project(':bitcoinj-core')