From 200e1f45f28f3cedb5050bdb661dae8c412f6811 Mon Sep 17 00:00:00 2001 From: Alpar Torok Date: Fri, 29 Jun 2018 19:17:19 +0000 Subject: [PATCH] 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 --- build.gradle | 18 +++-------- .../elasticsearch/gradle/BuildPlugin.groovy | 32 +++++++++++-------- .../gradle/plugin/PluginBuildPlugin.groovy | 10 +++--- .../test/StandaloneRestTestPlugin.groovy | 8 +++++ .../gradle/test/StandaloneTestPlugin.groovy | 7 ---- client/benchmark/build.gradle | 2 +- settings.gradle | 3 ++ x-pack/plugin/build.gradle | 2 +- x-pack/plugin/sql/jdbc/build.gradle | 2 +- 9 files changed, 43 insertions(+), 41 deletions(-) diff --git a/build.gradle b/build.gradle index 862943b50f5..a29c7834221 100644 --- a/build.gradle +++ b/build.gradle @@ -486,25 +486,17 @@ task run(type: Run) { impliesSubProjects = true } -task wrapper(type: Wrapper) - -gradle.projectsEvaluated { - - allprojects { - tasks.withType(Wrapper) { Wrapper wrapper -> - wrapper.distributionType = DistributionType.ALL - - wrapper.doLast { +wrapper { + distributionType = DistributionType.ALL + doLast { final DistributionLocator locator = new DistributionLocator() final GradleVersion version = GradleVersion.version(wrapper.gradleVersion) final URI distributionUri = locator.getDistributionFor(version, wrapper.distributionType.name().toLowerCase(Locale.ENGLISH)) final URI sha256Uri = new URI(distributionUri.toString() + ".sha256") final String sha256Sum = new String(sha256Uri.toURL().bytes) wrapper.getPropertiesFile() << "distributionSha256Sum=${sha256Sum}\n" - } + println "Added checksum to wrapper properties" } - } - } static void assertLinesInFile(final Path path, final List expectedLines) { @@ -591,7 +583,7 @@ if (System.properties.get("build.compare") != null) { } } sourceBuild { - gradleVersion = "4.7" // does not default to gradle weapper of project dir, but current version + gradleVersion = "4.8.1" // does not default to gradle weapper of project dir, but current version projectDir = referenceProject tasks = ["clean", "assemble"] arguments = ["-Dbuild.compare_friendly=true"] diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy index 79f0c744c10..04fcbe0776b 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy @@ -471,6 +471,24 @@ class BuildPlugin implements Plugin { /**Configuration generation of maven poms. */ public static void configurePomGeneration(Project project) { + // Only works with `enableFeaturePreview('STABLE_PUBLISHING')` + // https://github.com/gradle/gradle/issues/5696#issuecomment-396965185 + project.tasks.withType(GenerateMavenPom.class) { GenerateMavenPom generatePOMTask -> + // The GenerateMavenPom task is aggressive about setting the destination, instead of fighting it, + // just make a copy. + doLast { + project.copy { + from generatePOMTask.destination + into "${project.buildDir}/distributions" + rename { "${project.archivesBaseName}-${project.version}.pom" } + } + } + // build poms with assemble (if the assemble task exists) + Task assemble = project.tasks.findByName('assemble') + if (assemble) { + assemble.dependsOn(generatePOMTask) + } + } project.plugins.withType(MavenPublishPlugin.class).whenPluginAdded { project.publishing { publications { @@ -480,20 +498,6 @@ class BuildPlugin implements Plugin { } } } - - // 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) - } - } - } } } diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy index 0a60d6ef87a..eb4da8d1f31 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy @@ -159,16 +159,18 @@ public class PluginBuildPlugin extends BuildPlugin { /** Adds a task to move jar and associated files to a "-client" name. */ protected static void addClientJarTask(Project project) { Task clientJar = project.tasks.create('clientJar') - clientJar.dependsOn(project.jar, 'generatePomFileForClientJarPublication', project.javadocJar, project.sourcesJar) + clientJar.dependsOn(project.jar, project.tasks.generatePomFileForClientJarPublication, project.javadocJar, project.sourcesJar) clientJar.doFirst { Path jarFile = project.jar.outputs.files.singleFile.toPath() String clientFileName = jarFile.fileName.toString().replace(project.version, "client-${project.version}") Files.copy(jarFile, jarFile.resolveSibling(clientFileName), StandardCopyOption.REPLACE_EXISTING) - String pomFileName = jarFile.fileName.toString().replace('.jar', '.pom') String clientPomFileName = clientFileName.replace('.jar', '.pom') - Files.copy(jarFile.resolveSibling(pomFileName), jarFile.resolveSibling(clientPomFileName), - StandardCopyOption.REPLACE_EXISTING) + Files.copy( + project.tasks.generatePomFileForClientJarPublication.outputs.files.singleFile.toPath(), + jarFile.resolveSibling(clientPomFileName), + StandardCopyOption.REPLACE_EXISTING + ) String sourcesFileName = jarFile.fileName.toString().replace('.jar', '-sources.jar') String clientSourcesFileName = clientFileName.replace('.jar', '-sources.jar') diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneRestTestPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneRestTestPlugin.groovy index c48dc890ab0..390821c80ff 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneRestTestPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneRestTestPlugin.groovy @@ -29,6 +29,7 @@ import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.plugins.JavaBasePlugin +import org.gradle.api.tasks.compile.JavaCompile /** * Configures the build to compile tests against Elasticsearch's test framework @@ -61,5 +62,12 @@ public class StandaloneRestTestPlugin implements Plugin { PrecommitTasks.create(project, false) project.check.dependsOn(project.precommit) + + project.tasks.withType(JavaCompile) { + // This will be the default in Gradle 5.0 + if (options.compilerArgs.contains("-processor") == false) { + options.compilerArgs << '-proc:none' + } + } } } diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneTestPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneTestPlugin.groovy index 3e1f62f96e6..e38163d6166 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneTestPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneTestPlugin.groovy @@ -50,12 +50,5 @@ public class StandaloneTestPlugin implements Plugin { test.testClassesDirs = project.sourceSets.test.output.classesDirs test.mustRunAfter(project.precommit) project.check.dependsOn(test) - - project.tasks.withType(JavaCompile) { - // This will be the default in Gradle 5.0 - if (options.compilerArgs.contains("-processor") == false) { - options.compilerArgs << '-proc:none' - } - } } } diff --git a/client/benchmark/build.gradle b/client/benchmark/build.gradle index 5d557207ea3..77867f5e273 100644 --- a/client/benchmark/build.gradle +++ b/client/benchmark/build.gradle @@ -24,7 +24,7 @@ buildscript { } } dependencies { - classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.2' + classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4' } } diff --git a/settings.gradle b/settings.gradle index 7a72baf1c41..5904cc4daf4 100644 --- a/settings.gradle +++ b/settings.gradle @@ -128,3 +128,6 @@ if (extraProjects.exists()) { addSubProjects('', extraProjectDir) } } + +// enable in preparation for Gradle 5.0 +enableFeaturePreview('STABLE_PUBLISHING') diff --git a/x-pack/plugin/build.gradle b/x-pack/plugin/build.gradle index 919663c57cb..20ae41f10dc 100644 --- a/x-pack/plugin/build.gradle +++ b/x-pack/plugin/build.gradle @@ -36,7 +36,7 @@ subprojects { // default to main class files if such a source set exists final List files = [] if (project.sourceSets.findByName("main")) { - files.add(project.sourceSets.main.output.classesDir) + files.add(project.sourceSets.main.output.classesDirs) dependsOn project.tasks.classes } // filter out non-existent classes directories from empty source sets diff --git a/x-pack/plugin/sql/jdbc/build.gradle b/x-pack/plugin/sql/jdbc/build.gradle index ca8d966a031..9d27c2030d6 100644 --- a/x-pack/plugin/sql/jdbc/build.gradle +++ b/x-pack/plugin/sql/jdbc/build.gradle @@ -6,7 +6,7 @@ buildscript { } } dependencies { - classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.2' + classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4' } }