Skip to content

Commit 8a77ce4

Browse files
committed
Upgrade gradle wrapper to 4.8 (#31525)
* Move to Gradle 4.8 RC1 * Use latest version of plugin The current does not work with Gradle 4.8 RC1 * Switch to Gradle GA * Add and configure build compare plugin * add work-around for gradle/gradle#5692 * work around gradle/gradle#5696 * Make use of Gradle build compare with reference project * Make the manifest more compare friendly * Clear the manifest in compare friendly mode * Remove animalsniffer from buildscript classpath * Fix javadoc errors * Fix doc issues * reference Gradle issues in comments * Conditionally configure build compare * Fix some more doclint issues * fix typo in build script * Add sanity check to make sure the test task was replaced Relates to #31324. It seems like Gradle has an inconsistent behavior and the taks is not always replaced. * Include number of non conforming tasks in the exception. * No longer replace test task, create implicit instead Closes #31324. The issue has full context in comments. With this change the `test` task becomes nothing more than an alias for `utest`. Some of the stand alone tests that had a `test` task now have `integTest`, and a few of them that used to have `integTest` to run multiple tests now only have `check`. This will also help separarate unit/micro tests from integration tests. * Revert "No longer replace test task, create implicit instead" This reverts commit f1ebaf7. * Fix replacement of the test task Based on information from gradle/gradle#5730 replace the task taking into account the task providres. Closes #31324. * Only apply build comapare plugin if needed * Make sure test runs before integTest * Fix doclint aftter merge * PR review comments * Switch to Gradle 4.8.1 and remove workaround * PR review comments * Consolidate task ordering
1 parent 7d17af9 commit 8a77ce4

File tree

28 files changed

+127
-73
lines changed

28 files changed

+127
-73
lines changed

benchmarks/build.gradle

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ buildscript {
2929
}
3030

3131
apply plugin: 'elasticsearch.build'
32-
// build an uberjar with all benchmarks
33-
apply plugin: 'com.github.johnrengelman.shadow'
34-
// have the shadow plugin provide the runShadow task
35-
apply plugin: 'application'
32+
33+
// order of this section matters, see: https://github.com/johnrengelman/shadow/issues/336
34+
apply plugin: 'application' // have the shadow plugin provide the runShadow task
35+
mainClassName = 'org.openjdk.jmh.Main'
36+
apply plugin: 'com.github.johnrengelman.shadow' // build an uberjar with all benchmarks
3637

3738
// Not published so no need to assemble
3839
tasks.remove(assemble)

build.gradle

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ gradle.projectsEvaluated {
320320
// :test:framework:test cannot run before and after :server:test
321321
return
322322
}
323+
if (tasks.findByPath('test') != null && tasks.findByPath('integTest') != null) {
324+
integTest.mustRunAfter test
325+
}
323326
configurations.all { Configuration configuration ->
324327
/*
325328
* The featureAwarePlugin configuration has a dependency on x-pack:plugin:core and x-pack:plugin:core has a dependency on the
@@ -569,3 +572,28 @@ gradle.projectsEvaluated {
569572
}
570573
}
571574
}
575+
576+
if (System.properties.get("build.compare") != null) {
577+
apply plugin: 'compare-gradle-builds'
578+
compareGradleBuilds {
579+
ext.referenceProject = System.properties.get("build.compare")
580+
doFirst {
581+
if (file(referenceProject).exists() == false) {
582+
throw new GradleException(
583+
"Use git worktree to check out a version to compare against to ../elasticsearch_build_reference"
584+
)
585+
}
586+
}
587+
sourceBuild {
588+
gradleVersion = "4.7" // does not default to gradle weapper of project dir, but current version
589+
projectDir = referenceProject
590+
tasks = ["clean", "assemble"]
591+
arguments = ["-Dbuild.compare_friendly=true"]
592+
}
593+
targetBuild {
594+
tasks = ["clean", "assemble"]
595+
// use -Dorg.gradle.java.home= to alter jdk versions
596+
arguments = ["-Dbuild.compare_friendly=true"]
597+
}
598+
}
599+
}

buildSrc/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ GradleVersion logVersion = GradleVersion.current() > GradleVersion.version('4.3'
106106

107107
dependencies {
108108
compileOnly "org.gradle:gradle-logging:${logVersion.getVersion()}"
109-
compile 'ru.vyarus:gradle-animalsniffer-plugin:1.2.0' // Gradle 2.14 requires a version > 1.0.1
110109
}
111110

112111
/*****************************************************************************

buildSrc/src/main/groovy/com/carrotsearch/gradle/junit4/RandomizedTestingPlugin.groovy

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,44 @@
11
package com.carrotsearch.gradle.junit4
22

33
import com.carrotsearch.ant.tasks.junit4.JUnit4
4-
import org.gradle.api.AntBuilder
4+
import org.gradle.api.GradleException
55
import org.gradle.api.Plugin
66
import org.gradle.api.Project
77
import org.gradle.api.Task
8+
import org.gradle.api.UnknownTaskException
89
import org.gradle.api.plugins.JavaBasePlugin
910
import org.gradle.api.tasks.TaskContainer
11+
import org.gradle.api.tasks.TaskProvider
1012
import org.gradle.api.tasks.testing.Test
1113

14+
import java.util.concurrent.atomic.AtomicBoolean
15+
1216
class RandomizedTestingPlugin implements Plugin<Project> {
1317

18+
static private AtomicBoolean sanityCheckConfigured = new AtomicBoolean(false)
19+
1420
void apply(Project project) {
1521
setupSeed(project)
1622
replaceTestTask(project.tasks)
1723
configureAnt(project.ant)
24+
configureSanityCheck(project)
25+
}
26+
27+
private static void configureSanityCheck(Project project) {
28+
// Check the task graph to confirm tasks were indeed replaced
29+
// https://github.com/elastic/elasticsearch/issues/31324
30+
if (sanityCheckConfigured.getAndSet(true) == false) {
31+
project.rootProject.getGradle().getTaskGraph().whenReady {
32+
List<Task> nonConforming = project.getGradle().getTaskGraph().allTasks
33+
.findAll { it.name == "test" }
34+
.findAll { (it instanceof RandomizedTestingTask) == false}
35+
.collect { "${it.path} -> ${it.class}" }
36+
if (nonConforming.isEmpty() == false) {
37+
throw new GradleException("Found the ${nonConforming.size()} `test` tasks:" +
38+
"\n ${nonConforming.join("\n ")}")
39+
}
40+
}
41+
}
1842
}
1943

2044
/**
@@ -45,29 +69,32 @@ class RandomizedTestingPlugin implements Plugin<Project> {
4569
}
4670

4771
static void replaceTestTask(TaskContainer tasks) {
48-
Test oldTestTask = tasks.findByPath('test')
49-
if (oldTestTask == null) {
72+
// Gradle 4.8 introduced lazy tasks, thus we deal both with the `test` task as well as it's provider
73+
// https://github.com/gradle/gradle/issues/5730#issuecomment-398822153
74+
// since we can't be sure if the task was ever realized, we remove both the provider and the task
75+
TaskProvider<Test> oldTestProvider
76+
try {
77+
oldTestProvider = tasks.getByNameLater(Test, 'test')
78+
} catch (UnknownTaskException unused) {
5079
// no test task, ok, user will use testing task on their own
5180
return
5281
}
53-
tasks.remove(oldTestTask)
82+
Test oldTestTask = oldTestProvider.get()
5483

55-
Map properties = [
56-
name: 'test',
57-
type: RandomizedTestingTask,
58-
dependsOn: oldTestTask.dependsOn,
59-
group: JavaBasePlugin.VERIFICATION_GROUP,
60-
description: 'Runs unit tests with the randomized testing framework'
61-
]
62-
RandomizedTestingTask newTestTask = tasks.create(properties)
63-
newTestTask.classpath = oldTestTask.classpath
64-
newTestTask.testClassesDir = oldTestTask.project.sourceSets.test.output.classesDir
65-
// since gradle 4.5, tasks immutable dependencies are "hidden" (do not show up in dependsOn)
66-
// so we must explicitly add a dependency on generating the test classpath
67-
newTestTask.dependsOn('testClasses')
84+
// we still have to use replace here despite the remove above because the task container knows about the provider
85+
// by the same name
86+
RandomizedTestingTask newTestTask = tasks.replace('test', RandomizedTestingTask)
87+
newTestTask.configure{
88+
group = JavaBasePlugin.VERIFICATION_GROUP
89+
description = 'Runs unit tests with the randomized testing framework'
90+
dependsOn oldTestTask.dependsOn, 'testClasses'
91+
classpath = oldTestTask.classpath
92+
testClassesDir = oldTestTask.project.sourceSets.test.output.classesDir
93+
}
6894

6995
// hack so check task depends on custom test
70-
Task checkTask = tasks.findByPath('check')
96+
Task checkTask = tasks.getByName('check')
97+
checkTask.dependsOn.remove(oldTestProvider)
7198
checkTask.dependsOn.remove(oldTestTask)
7299
checkTask.dependsOn.add(newTestTask)
73100
}

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,9 @@ class BuildPlugin implements Plugin<Project> {
348348
// just a self contained test-fixture configuration, likely transitive and hellacious
349349
return
350350
}
351-
configuration.resolutionStrategy.failOnVersionConflict()
351+
configuration.resolutionStrategy {
352+
failOnVersionConflict()
353+
}
352354
})
353355

354356
// force all dependencies added directly to compile/testCompile to be non-transitive, except for ES itself
@@ -475,13 +477,17 @@ class BuildPlugin implements Plugin<Project> {
475477
}
476478
}
477479

478-
project.tasks.withType(GenerateMavenPom.class) { GenerateMavenPom t ->
479-
// place the pom next to the jar it is for
480-
t.destination = new File(project.buildDir, "distributions/${project.archivesBaseName}-${project.version}.pom")
481-
// build poms with assemble (if the assemble task exists)
482-
Task assemble = project.tasks.findByName('assemble')
483-
if (assemble) {
484-
assemble.dependsOn(t)
480+
// Work around Gradle 4.8 issue until we `enableFeaturePreview('STABLE_PUBLISHING')`
481+
// https://github.com/gradle/gradle/issues/5696#issuecomment-396965185
482+
project.getGradle().getTaskGraph().whenReady {
483+
project.tasks.withType(GenerateMavenPom.class) { GenerateMavenPom t ->
484+
// place the pom next to the jar it is for
485+
t.destination = new File(project.buildDir, "distributions/${project.archivesBaseName}-${project.version}.pom")
486+
// build poms with assemble (if the assemble task exists)
487+
Task assemble = project.tasks.findByName('assemble')
488+
if (assemble) {
489+
assemble.dependsOn(t)
490+
}
485491
}
486492
}
487493
}
@@ -625,6 +631,10 @@ class BuildPlugin implements Plugin<Project> {
625631
jarTask.manifest.attributes('Change': shortHash)
626632
}
627633
}
634+
// Force manifest entries that change by nature to a constant to be able to compare builds more effectively
635+
if (System.properties.getProperty("build.compare_friendly", "false") == "true") {
636+
jarTask.manifest.getAttributes().clear()
637+
}
628638
}
629639
// add license/notice files
630640
project.afterEvaluate {

client/rest/src/main/java/org/elasticsearch/client/RestClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,8 +1010,8 @@ public int compareTo(DeadNode rhs) {
10101010
}
10111011

10121012
/**
1013-
* Adapts an <code>Iterator<DeadNodeAndRevival></code> into an
1014-
* <code>Iterator<Node></code>.
1013+
* Adapts an <code>Iterator&lt;DeadNodeAndRevival&gt;</code> into an
1014+
* <code>Iterator&lt;Node&gt;</code>.
10151015
*/
10161016
private static class DeadNodeIteratorAdapter implements Iterator<Node> {
10171017
private final Iterator<DeadNode> itr;

client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ public void testBody() throws IOException {
314314
}
315315

316316
/**
317-
* @deprecated will remove method in 7.0 but needs tests until then. Replaced by {@link RequestTests#testAddHeaders()}.
317+
* @deprecated will remove method in 7.0 but needs tests until then. Replaced by {@link RequestTests}.
318318
*/
319319
@Deprecated
320320
public void tesPerformRequestOldStyleNullHeaders() throws IOException {

client/rest/src/test/java/org/elasticsearch/client/RestClientTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public void onFailure(Exception exception) {
141141
}
142142

143143
/**
144-
* @deprecated will remove method in 7.0 but needs tests until then. Replaced by {@link RequestTests#testAddHeader()}.
144+
* @deprecated will remove method in 7.0 but needs tests until then. Replaced by {@link RequestTests}.
145145
*/
146146
@Deprecated
147147
public void testPerformOldStyleAsyncWithNullHeaders() throws Exception {

gradle/wrapper/gradle-wrapper.jar

88 Bytes
Binary file not shown.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
4-
zipStorePath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-all.zip
54
zipStoreBase=GRADLE_USER_HOME
6-
distributionSha256Sum=203f4537da8b8075e38c036a6d14cb71b1149de5bf0a8f6db32ac2833a1d1294
5+
zipStorePath=wrapper/dists
6+
distributionSha256Sum=ce1645ff129d11aad62dab70d63426fdce6cfd646fa309dc5dc5255dd03c7c11

0 commit comments

Comments
 (0)