Skip to content

Commit 79cdcee

Browse files
committed
Fix gradle4.8 deprecation warnings (#31654)
* remove explicit wrapper task It's created by Gradle and triggers a deprecation warning Simplify configuration * Upgrade shadow plugin to get rid of Gradle deprecation * Move compile configuration to base plugin Solves Gradle deprecation warning from earlier Gradle versions * Enable stable publishing in the Gradle build * Replace usage of deprecated property * bump Gradle version in build compare
1 parent 251b4fc commit 79cdcee

File tree

8 files changed

+43
-34
lines changed

8 files changed

+43
-34
lines changed

build.gradle

+5-13
Original file line numberDiff line numberDiff line change
@@ -480,25 +480,17 @@ task run(type: Run) {
480480
impliesSubProjects = true
481481
}
482482

483-
task wrapper(type: Wrapper)
484-
485-
gradle.projectsEvaluated {
486-
487-
allprojects {
488-
tasks.withType(Wrapper) { Wrapper wrapper ->
489-
wrapper.distributionType = DistributionType.ALL
490-
491-
wrapper.doLast {
483+
wrapper {
484+
distributionType = DistributionType.ALL
485+
doLast {
492486
final DistributionLocator locator = new DistributionLocator()
493487
final GradleVersion version = GradleVersion.version(wrapper.gradleVersion)
494488
final URI distributionUri = locator.getDistributionFor(version, wrapper.distributionType.name().toLowerCase(Locale.ENGLISH))
495489
final URI sha256Uri = new URI(distributionUri.toString() + ".sha256")
496490
final String sha256Sum = new String(sha256Uri.toURL().bytes)
497491
wrapper.getPropertiesFile() << "distributionSha256Sum=${sha256Sum}\n"
498-
}
492+
println "Added checksum to wrapper properties"
499493
}
500-
}
501-
502494
}
503495

504496
static void assertLinesInFile(final Path path, final List<String> expectedLines) {
@@ -585,7 +577,7 @@ if (System.properties.get("build.compare") != null) {
585577
}
586578
}
587579
sourceBuild {
588-
gradleVersion = "4.7" // does not default to gradle weapper of project dir, but current version
580+
gradleVersion = "4.8.1" // does not default to gradle weapper of project dir, but current version
589581
projectDir = referenceProject
590582
tasks = ["clean", "assemble"]
591583
arguments = ["-Dbuild.compare_friendly=true"]

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

+18-14
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,24 @@ class BuildPlugin implements Plugin<Project> {
471471

472472
/**Configuration generation of maven poms. */
473473
public static void configurePomGeneration(Project project) {
474+
// Only works with `enableFeaturePreview('STABLE_PUBLISHING')`
475+
// https://github.com/gradle/gradle/issues/5696#issuecomment-396965185
476+
project.tasks.withType(GenerateMavenPom.class) { GenerateMavenPom generatePOMTask ->
477+
// The GenerateMavenPom task is aggressive about setting the destination, instead of fighting it,
478+
// just make a copy.
479+
doLast {
480+
project.copy {
481+
from generatePOMTask.destination
482+
into "${project.buildDir}/distributions"
483+
rename { "${project.archivesBaseName}-${project.version}.pom" }
484+
}
485+
}
486+
// build poms with assemble (if the assemble task exists)
487+
Task assemble = project.tasks.findByName('assemble')
488+
if (assemble) {
489+
assemble.dependsOn(generatePOMTask)
490+
}
491+
}
474492
project.plugins.withType(MavenPublishPlugin.class).whenPluginAdded {
475493
project.publishing {
476494
publications {
@@ -480,20 +498,6 @@ class BuildPlugin implements Plugin<Project> {
480498
}
481499
}
482500
}
483-
484-
// Work around Gradle 4.8 issue until we `enableFeaturePreview('STABLE_PUBLISHING')`
485-
// https://github.com/gradle/gradle/issues/5696#issuecomment-396965185
486-
project.getGradle().getTaskGraph().whenReady {
487-
project.tasks.withType(GenerateMavenPom.class) { GenerateMavenPom t ->
488-
// place the pom next to the jar it is for
489-
t.destination = new File(project.buildDir, "distributions/${project.archivesBaseName}-${project.version}.pom")
490-
// build poms with assemble (if the assemble task exists)
491-
Task assemble = project.tasks.findByName('assemble')
492-
if (assemble) {
493-
assemble.dependsOn(t)
494-
}
495-
}
496-
}
497501
}
498502
}
499503

buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy

+6-4
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,18 @@ public class PluginBuildPlugin extends BuildPlugin {
157157
/** Adds a task to move jar and associated files to a "-client" name. */
158158
protected static void addClientJarTask(Project project) {
159159
Task clientJar = project.tasks.create('clientJar')
160-
clientJar.dependsOn(project.jar, 'generatePomFileForClientJarPublication', project.javadocJar, project.sourcesJar)
160+
clientJar.dependsOn(project.jar, project.tasks.generatePomFileForClientJarPublication, project.javadocJar, project.sourcesJar)
161161
clientJar.doFirst {
162162
Path jarFile = project.jar.outputs.files.singleFile.toPath()
163163
String clientFileName = jarFile.fileName.toString().replace(project.version, "client-${project.version}")
164164
Files.copy(jarFile, jarFile.resolveSibling(clientFileName), StandardCopyOption.REPLACE_EXISTING)
165165

166-
String pomFileName = jarFile.fileName.toString().replace('.jar', '.pom')
167166
String clientPomFileName = clientFileName.replace('.jar', '.pom')
168-
Files.copy(jarFile.resolveSibling(pomFileName), jarFile.resolveSibling(clientPomFileName),
169-
StandardCopyOption.REPLACE_EXISTING)
167+
Files.copy(
168+
project.tasks.generatePomFileForClientJarPublication.outputs.files.singleFile.toPath(),
169+
jarFile.resolveSibling(clientPomFileName),
170+
StandardCopyOption.REPLACE_EXISTING
171+
)
170172

171173
String sourcesFileName = jarFile.fileName.toString().replace('.jar', '-sources.jar')
172174
String clientSourcesFileName = clientFileName.replace('.jar', '-sources.jar')

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneRestTestPlugin.groovy

+8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import org.gradle.api.Plugin
2929
import org.gradle.api.Project
3030
import org.gradle.api.Task
3131
import org.gradle.api.plugins.JavaBasePlugin
32+
import org.gradle.api.tasks.compile.JavaCompile
3233

3334
/**
3435
* Configures the build to compile tests against Elasticsearch's test framework
@@ -61,5 +62,12 @@ public class StandaloneRestTestPlugin implements Plugin<Project> {
6162

6263
PrecommitTasks.create(project, false)
6364
project.check.dependsOn(project.precommit)
65+
66+
project.tasks.withType(JavaCompile) {
67+
// This will be the default in Gradle 5.0
68+
if (options.compilerArgs.contains("-processor") == false) {
69+
options.compilerArgs << '-proc:none'
70+
}
71+
}
6472
}
6573
}

client/benchmark/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ buildscript {
2424
}
2525
}
2626
dependencies {
27-
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.2'
27+
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
2828
}
2929
}
3030

settings.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,6 @@ if (extraProjects.exists()) {
123123
addSubProjects('', extraProjectDir)
124124
}
125125
}
126+
127+
// enable in preparation for Gradle 5.0
128+
enableFeaturePreview('STABLE_PUBLISHING')

x-pack/plugin/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ subprojects {
3636
// default to main class files if such a source set exists
3737
final List files = []
3838
if (project.sourceSets.findByName("main")) {
39-
files.add(project.sourceSets.main.output.classesDir)
39+
files.add(project.sourceSets.main.output.classesDirs)
4040
dependsOn project.tasks.classes
4141
}
4242
// filter out non-existent classes directories from empty source sets

x-pack/plugin/sql/jdbc/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
}
77
}
88
dependencies {
9-
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.2'
9+
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
1010
}
1111
}
1212

0 commit comments

Comments
 (0)