-
Notifications
You must be signed in to change notification settings - Fork 25.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade gradle wrapper to 4.8 #31525
Changes from all commits
70effe4
ac5b3b1
541ae72
fc0667d
b0c9ff4
b18dc30
d6479de
bbb2f9a
302f171
50b7c3c
db8ebd3
869a84b
a54139c
db92ced
93213ab
46fefdc
5e53dee
9eaa07e
6ccfec8
e141e4b
6ae2a7b
05b966c
ba43cc1
505ab68
f2edc18
e648dce
21c72f9
ca88789
ca48ace
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,44 @@ | ||
package com.carrotsearch.gradle.junit4 | ||
|
||
import com.carrotsearch.ant.tasks.junit4.JUnit4 | ||
import org.gradle.api.AntBuilder | ||
import org.gradle.api.GradleException | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.api.Task | ||
import org.gradle.api.UnknownTaskException | ||
import org.gradle.api.plugins.JavaBasePlugin | ||
import org.gradle.api.tasks.TaskContainer | ||
import org.gradle.api.tasks.TaskProvider | ||
import org.gradle.api.tasks.testing.Test | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean | ||
|
||
class RandomizedTestingPlugin implements Plugin<Project> { | ||
|
||
static private AtomicBoolean sanityCheckConfigured = new AtomicBoolean(false) | ||
|
||
void apply(Project project) { | ||
setupSeed(project) | ||
replaceTestTask(project.tasks) | ||
configureAnt(project.ant) | ||
configureSanityCheck(project) | ||
} | ||
|
||
private static void configureSanityCheck(Project project) { | ||
// Check the task graph to confirm tasks were indeed replaced | ||
// https://github.com/elastic/elasticsearch/issues/31324 | ||
if (sanityCheckConfigured.getAndSet(true) == false) { | ||
project.rootProject.getGradle().getTaskGraph().whenReady { | ||
List<Task> nonConforming = project.getGradle().getTaskGraph().allTasks | ||
.findAll { it.name == "test" } | ||
.findAll { (it instanceof RandomizedTestingTask) == false} | ||
.collect { "${it.path} -> ${it.class}" } | ||
if (nonConforming.isEmpty() == false) { | ||
throw new GradleException("Found the ${nonConforming.size()} `test` tasks:" + | ||
"\n ${nonConforming.join("\n ")}") | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -45,29 +69,32 @@ class RandomizedTestingPlugin implements Plugin<Project> { | |
} | ||
|
||
static void replaceTestTask(TaskContainer tasks) { | ||
Test oldTestTask = tasks.findByPath('test') | ||
if (oldTestTask == null) { | ||
// Gradle 4.8 introduced lazy tasks, thus we deal both with the `test` task as well as it's provider | ||
// https://github.com/gradle/gradle/issues/5730#issuecomment-398822153 | ||
// since we can't be sure if the task was ever realized, we remove both the provider and the task | ||
TaskProvider<Test> oldTestProvider | ||
try { | ||
oldTestProvider = tasks.getByNameLater(Test, 'test') | ||
} catch (UnknownTaskException unused) { | ||
// no test task, ok, user will use testing task on their own | ||
return | ||
} | ||
tasks.remove(oldTestTask) | ||
Test oldTestTask = oldTestProvider.get() | ||
|
||
Map properties = [ | ||
name: 'test', | ||
type: RandomizedTestingTask, | ||
dependsOn: oldTestTask.dependsOn, | ||
group: JavaBasePlugin.VERIFICATION_GROUP, | ||
description: 'Runs unit tests with the randomized testing framework' | ||
] | ||
RandomizedTestingTask newTestTask = tasks.create(properties) | ||
newTestTask.classpath = oldTestTask.classpath | ||
newTestTask.testClassesDir = oldTestTask.project.sourceSets.test.output.classesDir | ||
// since gradle 4.5, tasks immutable dependencies are "hidden" (do not show up in dependsOn) | ||
// so we must explicitly add a dependency on generating the test classpath | ||
newTestTask.dependsOn('testClasses') | ||
// we still have to use replace here despite the remove above because the task container knows about the provider | ||
// by the same name | ||
RandomizedTestingTask newTestTask = tasks.replace('test', RandomizedTestingTask) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need remove at all then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, we don't need to remove with replace. |
||
newTestTask.configure{ | ||
group = JavaBasePlugin.VERIFICATION_GROUP | ||
description = 'Runs unit tests with the randomized testing framework' | ||
dependsOn oldTestTask.dependsOn, 'testClasses' | ||
classpath = oldTestTask.classpath | ||
testClassesDir = oldTestTask.project.sourceSets.test.output.classesDir | ||
} | ||
|
||
// hack so check task depends on custom test | ||
Task checkTask = tasks.findByPath('check') | ||
Task checkTask = tasks.getByName('check') | ||
checkTask.dependsOn.remove(oldTestProvider) | ||
checkTask.dependsOn.remove(oldTestTask) | ||
checkTask.dependsOn.add(newTestTask) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -348,7 +348,9 @@ class BuildPlugin implements Plugin<Project> { | |
// just a self contained test-fixture configuration, likely transitive and hellacious | ||
return | ||
} | ||
configuration.resolutionStrategy.failOnVersionConflict() | ||
configuration.resolutionStrategy { | ||
failOnVersionConflict() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did this change out of necessity? It was this way before to match what would be done in java (no closures in java). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's more for historic reasons, there was a work-around here with 4.8 that's no longer required in 4.8.1. With Java 8, as there's a functional interface I'm not entirely convinced about how useful keeping Java like syntax is Groovy will be in aiding conversion after having converted a few files in a different PR. Dynamic Groovy properties are by far harder to deal with than syntax. I would rater adopt a strategy going forward to convert files before doing any edits rather than caring for this syntax, it requires too much attention without it resulting in the end goal. |
||
} | ||
}) | ||
|
||
// 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> { | |
} | ||
} | ||
|
||
project.tasks.withType(GenerateMavenPom.class) { GenerateMavenPom t -> | ||
// place the pom next to the jar it is for | ||
t.destination = new File(project.buildDir, "distributions/${project.archivesBaseName}-${project.version}.pom") | ||
// build poms with assemble (if the assemble task exists) | ||
Task assemble = project.tasks.findByName('assemble') | ||
if (assemble) { | ||
assemble.dependsOn(t) | ||
// Work around Gradle 4.8 issue until we `enableFeaturePreview('STABLE_PUBLISHING')` | ||
// https://github.com/gradle/gradle/issues/5696#issuecomment-396965185 | ||
project.getGradle().getTaskGraph().whenReady { | ||
project.tasks.withType(GenerateMavenPom.class) { GenerateMavenPom t -> | ||
// place the pom next to the jar it is for | ||
t.destination = new File(project.buildDir, "distributions/${project.archivesBaseName}-${project.version}.pom") | ||
// build poms with assemble (if the assemble task exists) | ||
Task assemble = project.tasks.findByName('assemble') | ||
if (assemble) { | ||
assemble.dependsOn(t) | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -625,6 +631,10 @@ class BuildPlugin implements Plugin<Project> { | |
jarTask.manifest.attributes('Change': shortHash) | ||
} | ||
} | ||
// Force manifest entries that change by nature to a constant to be able to compare builds more effectively | ||
if (System.properties.getProperty("build.compare_friendly", "false") == "true") { | ||
jarTask.manifest.getAttributes().clear() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you elaborate more on this comment? I am concerned debug ability of a build that lacks any of the manifest info we inject. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This property should never be passed directly. It's being used by the build compare plugin. |
||
} | ||
} | ||
// add license/notice files | ||
project.afterEvaluate { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-all.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
distributionSha256Sum=203f4537da8b8075e38c036a6d14cb71b1149de5bf0a8f6db32ac2833a1d1294 | ||
zipStorePath=wrapper/dists | ||
distributionSha256Sum=ce1645ff129d11aad62dab70d63426fdce6cfd646fa309dc5dc5255dd03c7c11 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this atomic needed? When is the project ever applied more than once? I think a lot of our code would be broken if it were possible for multiple invocations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plugins is applied once per project, but it's done so on multiple projects.
Since there's a single task graph for all projects, and we must run the check on the task graph rather than the task collection ( as we ween the lather can look right and the former still has the wrong tasks ) we must make sure it's only done once.