Skip to content

Commit 04394be

Browse files
committed
Determine the minimum gradle version based on the wrapper (#32226)
* Determine the minimum gradle version based on the wrapper This is restrictive and forces users of the plugin to move together with us, but without integration tests it's close to impossible to make sure that the claimed compatability is really there. If we do want to offer more flexibility, we should add those tests first. * Track gradle version in individual file * PR review
1 parent 6f5b691 commit 04394be

File tree

5 files changed

+20
-19
lines changed

5 files changed

+20
-19
lines changed

build.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,17 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
2019
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
21-
import org.apache.tools.ant.taskdefs.condition.Os
22-
import org.apache.tools.ant.filters.ReplaceTokens
2320
import org.elasticsearch.gradle.BuildPlugin
2421
import org.elasticsearch.gradle.LoggedExec
2522
import org.elasticsearch.gradle.Version
2623
import org.elasticsearch.gradle.VersionCollection
2724
import org.elasticsearch.gradle.VersionProperties
2825
import org.gradle.plugins.ide.eclipse.model.SourceFolder
29-
30-
import org.gradle.api.tasks.wrapper.Wrapper
31-
import org.gradle.api.tasks.wrapper.Wrapper.DistributionType
3226
import org.gradle.util.GradleVersion
3327
import org.gradle.util.DistributionLocator
28+
import org.apache.tools.ant.taskdefs.condition.Os
29+
import org.apache.tools.ant.filters.ReplaceTokens
3430

3531
import java.nio.file.Files
3632
import java.nio.file.Path
@@ -556,7 +552,7 @@ task run(type: Run) {
556552
}
557553

558554
wrapper {
559-
distributionType = DistributionType.ALL
555+
distributionType = 'ALL'
560556
doLast {
561557
final DistributionLocator locator = new DistributionLocator()
562558
final GradleVersion version = GradleVersion.version(wrapper.gradleVersion)
@@ -565,6 +561,10 @@ wrapper {
565561
final String sha256Sum = new String(sha256Uri.toURL().bytes)
566562
wrapper.getPropertiesFile() << "distributionSha256Sum=${sha256Sum}\n"
567563
println "Added checksum to wrapper properties"
564+
// Update build-tools to reflect the Gradle upgrade
565+
// TODO: we can remove this once we have tests to make sure older versions work.
566+
project(':build-tools').file('src/main/resources/minimumGradleVersion').text = gradleVersion
567+
println "Updated minimum Gradle Version"
568568
}
569569
}
570570

buildSrc/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ plugins {
2525

2626
group = 'org.elasticsearch.gradle'
2727

28-
if (GradleVersion.current() < GradleVersion.version('4.9')) {
29-
throw new GradleException('Gradle 4.9+ is required to build elasticsearch')
28+
String minimumGradleVersion = file('src/main/resources/minimumGradleVersion').text.trim()
29+
if (GradleVersion.current() < GradleVersion.version(minimumGradleVersion)) {
30+
throw new GradleException("Gradle ${minimumGradleVersion}+ is required to build elasticsearch")
3031
}
3132

3233
if (JavaVersion.current() < JavaVersion.VERSION_1_8) {

buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package org.elasticsearch.gradle
2020

2121
import com.carrotsearch.gradle.junit4.RandomizedTestingTask
2222
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
23+
import org.apache.commons.io.IOUtils
2324
import org.apache.tools.ant.taskdefs.condition.Os
2425
import org.eclipse.jgit.lib.Constants
2526
import org.eclipse.jgit.lib.RepositoryBuilder
@@ -53,6 +54,7 @@ import org.gradle.internal.jvm.Jvm
5354
import org.gradle.process.ExecResult
5455
import org.gradle.util.GradleVersion
5556

57+
import java.nio.charset.StandardCharsets
5658
import java.time.ZoneOffset
5759
import java.time.ZonedDateTime
5860
/**
@@ -67,8 +69,13 @@ class BuildPlugin implements Plugin<Project> {
6769
+ 'elasticearch.standalone-rest-test, and elasticsearch.build '
6870
+ 'are mutually exclusive')
6971
}
70-
if (GradleVersion.current() < GradleVersion.version('4.9')) {
71-
throw new GradleException('Gradle 4.9+ is required to use elasticsearch.build plugin')
72+
final String minimumGradleVersion
73+
InputStream is = getClass().getResourceAsStream("/minimumGradleVersion")
74+
try { minimumGradleVersion = IOUtils.toString(is, StandardCharsets.UTF_8.toString()) } finally { is.close() }
75+
if (GradleVersion.current() < GradleVersion.version(minimumGradleVersion.trim())) {
76+
throw new GradleException(
77+
"Gradle ${minimumGradleVersion}+ is required to use elasticsearch.build plugin"
78+
)
7279
}
7380
project.pluginManager.apply('java')
7481
project.pluginManager.apply('carrotsearch.randomized-testing')
@@ -153,14 +160,6 @@ class BuildPlugin implements Plugin<Project> {
153160
}
154161
println " Random Testing Seed : ${project.testSeed}"
155162

156-
// enforce Gradle version
157-
final GradleVersion currentGradleVersion = GradleVersion.current();
158-
159-
final GradleVersion minGradle = GradleVersion.version('4.3')
160-
if (currentGradleVersion < minGradle) {
161-
throw new GradleException("${minGradle} or above is required to build Elasticsearch")
162-
}
163-
164163
// enforce Java version
165164
if (compilerJavaVersionEnum < minimumCompilerVersion) {
166165
final String message =
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4.9

gradle/wrapper/gradle-wrapper.jar

-4 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)