From 20c37efea2d9271a7ba87fc8534145366ed6e8ea Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Fri, 9 Feb 2018 11:30:24 -0800 Subject: [PATCH] Build: Replace provided configuration with compileOnly (#28564) When elasticsearch was originally moved to gradle, the "provided" equivalent in maven had to be done through a plugin. Since then, gradle added the "compileOnly" configuration. This commit removes the provided plugin and replaces all uses with compileOnly. --- build.gradle | 2 +- .../elasticsearch/gradle/BuildPlugin.groovy | 8 +++++--- .../gradle/plugin/PluginBuildPlugin.groovy | 14 +++++++------- .../precommit/NamingConventionsTask.groovy | 10 +++++----- .../precommit/ThirdPartyAuditTask.groovy | 18 +++++++++++------- distribution/tools/plugin-cli/build.gradle | 4 ++-- modules/percolator/build.gradle | 2 +- 7 files changed, 32 insertions(+), 26 deletions(-) diff --git a/build.gradle b/build.gradle index 980bb34bec3..487da892651 100644 --- a/build.gradle +++ b/build.gradle @@ -256,7 +256,7 @@ subprojects { } } project.configurations.compile.dependencies.findAll().toSorted(sortClosure).each(depJavadocClosure) - project.configurations.provided.dependencies.findAll().toSorted(sortClosure).each(depJavadocClosure) + project.configurations.compileOnly.dependencies.findAll().toSorted(sortClosure).each(depJavadocClosure) } } } diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy index 07218af3da9..4a8f6576358 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy @@ -76,7 +76,6 @@ class BuildPlugin implements Plugin { project.pluginManager.apply('nebula.info-java') project.pluginManager.apply('nebula.info-scm') project.pluginManager.apply('nebula.info-jar') - project.pluginManager.apply(ProvidedBasePlugin) globalBuildInfo(project) configureRepositories(project) @@ -261,6 +260,9 @@ class BuildPlugin implements Plugin { * to iterate the transitive dependencies and add excludes. */ static void configureConfigurations(Project project) { + // we want to test compileOnly deps! + project.configurations.testCompile.extendsFrom(project.configurations.compileOnly) + // we are not shipping these jars, we act like dumb consumers of these things if (project.path.startsWith(':test:fixtures') || project.path == ':build-tools') { return @@ -297,7 +299,7 @@ class BuildPlugin implements Plugin { project.configurations.compile.dependencies.all(disableTransitiveDeps) project.configurations.testCompile.dependencies.all(disableTransitiveDeps) - project.configurations.provided.dependencies.all(disableTransitiveDeps) + project.configurations.compileOnly.dependencies.all(disableTransitiveDeps) } /** Adds repositories used by ES dependencies */ @@ -665,7 +667,7 @@ class BuildPlugin implements Plugin { // only require dependency licenses for non-elasticsearch deps project.dependencyLicenses.dependencies = project.configurations.runtime.fileCollection { it.group.startsWith('org.elasticsearch') == false - } - project.configurations.provided + } - project.configurations.compileOnly } private static configureDependenciesInfo(Project project) { 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 950acad9a5e..062c1292956 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy @@ -90,15 +90,15 @@ public class PluginBuildPlugin extends BuildPlugin { private static void configureDependencies(Project project) { project.dependencies { - provided "org.elasticsearch:elasticsearch:${project.versions.elasticsearch}" + compileOnly "org.elasticsearch:elasticsearch:${project.versions.elasticsearch}" testCompile "org.elasticsearch.test:framework:${project.versions.elasticsearch}" // we "upgrade" these optional deps to provided for plugins, since they will run // with a full elasticsearch server that includes optional deps - provided "org.locationtech.spatial4j:spatial4j:${project.versions.spatial4j}" - provided "com.vividsolutions:jts:${project.versions.jts}" - provided "org.apache.logging.log4j:log4j-api:${project.versions.log4j}" - provided "org.apache.logging.log4j:log4j-core:${project.versions.log4j}" - provided "org.elasticsearch:jna:${project.versions.jna}" + compileOnly "org.locationtech.spatial4j:spatial4j:${project.versions.spatial4j}" + compileOnly "com.vividsolutions:jts:${project.versions.jts}" + compileOnly "org.apache.logging.log4j:log4j-api:${project.versions.log4j}" + compileOnly "org.apache.logging.log4j:log4j-core:${project.versions.log4j}" + compileOnly "org.elasticsearch:jna:${project.versions.jna}" } } @@ -133,7 +133,7 @@ public class PluginBuildPlugin extends BuildPlugin { } from pluginMetadata // metadata (eg custom security policy) from project.jar // this plugin's jar - from project.configurations.runtime - project.configurations.provided // the dep jars + from project.configurations.runtime - project.configurations.compileOnly // the dep jars // extra files for the plugin to go into the zip from('src/main/packaging') // TODO: move all config/bin/_size/etc into packaging from('src/main') { diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/NamingConventionsTask.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/NamingConventionsTask.groovy index 0feed8ccc4e..6050d4e278d 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/NamingConventionsTask.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/NamingConventionsTask.groovy @@ -74,10 +74,10 @@ public class NamingConventionsTask extends LoggedExec { "org.elasticsearch.gradle:build-tools:${VersionProperties.elasticsearch}") buildToolsDep.transitive = false // We don't need gradle in the classpath. It conflicts. } - FileCollection extraClasspath = project.configurations.namingConventions - dependsOn(extraClasspath) - - FileCollection classpath = project.sourceSets.test.runtimeClasspath + FileCollection classpath = project.files(project.configurations.namingConventions, + project.sourceSets.test.compileClasspath, + project.sourceSets.test.output) + dependsOn(classpath) inputs.files(classpath) description = "Tests that test classes aren't misnamed or misplaced" executable = new File(project.runtimeJavaHome, 'bin/java') @@ -95,7 +95,7 @@ public class NamingConventionsTask extends LoggedExec { project.afterEvaluate { doFirst { args('-Djna.nosys=true') - args('-cp', (classpath + extraClasspath).asPath, 'org.elasticsearch.test.NamingConventionsCheck') + args('-cp', classpath.asPath, 'org.elasticsearch.test.NamingConventionsCheck') args('--test-class', testClass) if (skipIntegTestInDisguise) { args('--skip-integ-tests-in-disguise') diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/ThirdPartyAuditTask.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/ThirdPartyAuditTask.groovy index 33ca6dccfa3..d6babbbfbb8 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/ThirdPartyAuditTask.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/ThirdPartyAuditTask.groovy @@ -74,14 +74,19 @@ public class ThirdPartyAuditTask extends AntTask { description = "Checks third party JAR bytecode for missing classes, use of internal APIs, and other horrors'"; project.afterEvaluate { - Configuration configuration = project.configurations.findByName('runtime'); + Configuration configuration = project.configurations.findByName('runtime') + Configuration compileOnly = project.configurations.findByName('compileOnly') if (configuration == null) { // some projects apparently do not have 'runtime'? what a nice inconsistency, // basically only serves to waste time in build logic! - configuration = project.configurations.findByName('testCompile'); + configuration = project.configurations.findByName('testCompile') + } + assert configuration != null + if (compileOnly == null) { + classpath = configuration + } else { + classpath = project.files(configuration, compileOnly) } - assert configuration != null; - classpath = configuration // we only want third party dependencies. jars = configuration.fileCollection({ dependency -> @@ -90,9 +95,8 @@ public class ThirdPartyAuditTask extends AntTask { // we don't want provided dependencies, which we have already scanned. e.g. don't // scan ES core's dependencies for every single plugin - Configuration provided = project.configurations.findByName('provided') - if (provided != null) { - jars -= provided + if (compileOnly != null) { + jars -= compileOnly } inputs.files(jars) onlyIf { jars.isEmpty() == false } diff --git a/distribution/tools/plugin-cli/build.gradle b/distribution/tools/plugin-cli/build.gradle index 374690e65ac..55ec44da25c 100644 --- a/distribution/tools/plugin-cli/build.gradle +++ b/distribution/tools/plugin-cli/build.gradle @@ -20,8 +20,8 @@ apply plugin: 'elasticsearch.build' dependencies { - provided "org.elasticsearch:elasticsearch:${version}" - provided "org.elasticsearch:elasticsearch-cli:${version}" + compileOnly "org.elasticsearch:elasticsearch:${version}" + compileOnly "org.elasticsearch:elasticsearch-cli:${version}" testCompile "org.elasticsearch.test:framework:${version}" testCompile 'com.google.jimfs:jimfs:1.1' testCompile 'com.google.guava:guava:18.0' diff --git a/modules/percolator/build.gradle b/modules/percolator/build.gradle index 066ae7bb1e0..db4a716af65 100644 --- a/modules/percolator/build.gradle +++ b/modules/percolator/build.gradle @@ -31,7 +31,7 @@ dependencyLicenses { // Don't check the client's license. We know it. dependencies = project.configurations.runtime.fileCollection { it.group.startsWith('org.elasticsearch') == false - } - project.configurations.provided + } - project.configurations.compileOnly } compileJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes"