From 376ef5ab5d31c52a3e8a7325e394e9158c20cb70 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Mon, 9 Jul 2018 12:13:40 -0400 Subject: [PATCH 1/6] HLREST: Bundle the x-pack protocol project The `:x-pack:protocol` project is an implementation detail shared by the xpack projects and the high level rest client and really doesn't deserve its own maven coordinants and published javadoc. This change bundles `:x-pack:protocol` into the high level rest client. Relates to #29827 --- client/rest-high-level/build.gradle | 49 ++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/client/rest-high-level/build.gradle b/client/rest-high-level/build.gradle index 05b1cb25ed5d0..cbe2597a35479 100644 --- a/client/rest-high-level/build.gradle +++ b/client/rest-high-level/build.gradle @@ -34,6 +34,19 @@ publishing { } } +// We bundle the x-pack:protocol project into the jar. +configurations { + bundled +} +sourceSets { + main { + compileClasspath += configurations.bundled + } + test { + compileClasspath += configurations.bundled + } +} + dependencies { compile "org.elasticsearch:elasticsearch:${version}" compile "org.elasticsearch.client:elasticsearch-rest-client:${version}" @@ -41,7 +54,12 @@ dependencies { compile "org.elasticsearch.plugin:aggs-matrix-stats-client:${version}" compile "org.elasticsearch.plugin:rank-eval-client:${version}" compile "org.elasticsearch.plugin:lang-mustache-client:${version}" - compile project(':x-pack:protocol') // TODO bundle into the jar + // Eclipse can't comprehend the bundled configuration... + if (isEclipse) { + compile project(':x-pack:protocol') + } else { + bundled project(':x-pack:protocol') + } testCompile "org.elasticsearch.client:test:${version}" testCompile "org.elasticsearch.test:framework:${version}" @@ -64,3 +82,32 @@ forbiddenApisMain { signaturesURLs += [PrecommitTasks.getResource('/forbidden/http-signatures.txt')] signaturesURLs += [file('src/main/resources/forbidden/rest-high-level-signatures.txt').toURI().toURL()] } + +javadoc { + // Bundle javadoc from all bundled projects into this project's javadoc + configurations.bundled.dependencies.all { Dependency dep -> + Project p = dependencyToProject(dep) + if (p != null) { + evaluationDependsOn(p.path) + source += p.sourceSets.main.allJava + } + } +} +jar { + from({configurations.bundled.collect { it.isDirectory() ? it : zipTree(it) }}) { + exclude 'META-INF/*' + } +} +/* + * Use the jar for testing so we have tests of the bundled jar. + */ +test { + classpath -= compileJava.outputs.files + classpath += jar.outputs.files + dependsOn jar +} +integTestRunner { + classpath -= compileJava.outputs.files + classpath += jar.outputs.files + dependsOn jar +} From ed5f1ea5c33e94a9fe71f02d96129844ee185d85 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Mon, 9 Jul 2018 13:01:56 -0400 Subject: [PATCH 2/6] Fix indentation --- client/rest-high-level/build.gradle | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/client/rest-high-level/build.gradle b/client/rest-high-level/build.gradle index cbe2597a35479..b1b1a5dd7be64 100644 --- a/client/rest-high-level/build.gradle +++ b/client/rest-high-level/build.gradle @@ -27,24 +27,24 @@ group = 'org.elasticsearch.client' archivesBaseName = 'elasticsearch-rest-high-level-client' publishing { - publications { - nebula { - artifactId = archivesBaseName - } + publications { + nebula { + artifactId = archivesBaseName } + } } // We bundle the x-pack:protocol project into the jar. configurations { - bundled + bundled } sourceSets { - main { - compileClasspath += configurations.bundled - } - test { - compileClasspath += configurations.bundled - } + main { + compileClasspath += configurations.bundled + } + test { + compileClasspath += configurations.bundled + } } dependencies { @@ -107,7 +107,7 @@ test { dependsOn jar } integTestRunner { - classpath -= compileJava.outputs.files - classpath += jar.outputs.files - dependsOn jar + classpath -= compileJava.outputs.files + classpath += jar.outputs.files + dependsOn jar } From 3260c3de66bb96449c5e7ecee2c088e7d9c2d399 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Tue, 10 Jul 2018 10:53:28 -0400 Subject: [PATCH 3/6] Switch to shadow! --- client/rest-high-level/build.gradle | 101 +++++++++++++++++++--------- 1 file changed, 68 insertions(+), 33 deletions(-) diff --git a/client/rest-high-level/build.gradle b/client/rest-high-level/build.gradle index b1b1a5dd7be64..a9b301a8783b4 100644 --- a/client/rest-high-level/build.gradle +++ b/client/rest-high-level/build.gradle @@ -1,5 +1,3 @@ -import org.elasticsearch.gradle.precommit.PrecommitTasks - /* * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with @@ -18,10 +16,26 @@ import org.elasticsearch.gradle.precommit.PrecommitTasks * specific language governing permissions and limitations * under the License. */ + +import org.elasticsearch.gradle.precommit.PrecommitTasks +import org.gradle.api.artifacts.ResolvedDependency + +buildscript { + repositories { + maven { + url 'https://plugins.gradle.org/m2/' + } + } + dependencies { + classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4' + } +} + apply plugin: 'elasticsearch.build' apply plugin: 'elasticsearch.rest-test' apply plugin: 'nebula.maven-base-publish' apply plugin: 'nebula.maven-scm' +apply plugin: 'com.github.johnrengelman.shadow' group = 'org.elasticsearch.client' archivesBaseName = 'elasticsearch-rest-high-level-client' @@ -34,32 +48,33 @@ publishing { } } -// We bundle the x-pack:protocol project into the jar. -configurations { - bundled -} +/* + * We need somewhere to configure dependencies that we don't wish to shade + * into the high level REST client. The shadow plugin creates a "shadow" + * configuration which is *almost* exactly that. It is never bundled into + * the shaded jar but is used for main source compilation. Unfortunately, + * by default it is not used for *test* source compilation and isn't used + * in tests at all. This change makes it available for test compilation. + * A change below makes it available for testing. + */ sourceSets { - main { - compileClasspath += configurations.bundled - } test { - compileClasspath += configurations.bundled + compileClasspath += configurations.shadow } } dependencies { - compile "org.elasticsearch:elasticsearch:${version}" - compile "org.elasticsearch.client:elasticsearch-rest-client:${version}" - compile "org.elasticsearch.plugin:parent-join-client:${version}" - compile "org.elasticsearch.plugin:aggs-matrix-stats-client:${version}" - compile "org.elasticsearch.plugin:rank-eval-client:${version}" - compile "org.elasticsearch.plugin:lang-mustache-client:${version}" - // Eclipse can't comprehend the bundled configuration... - if (isEclipse) { - compile project(':x-pack:protocol') - } else { - bundled project(':x-pack:protocol') - } + /* + * Everything in the "shadow" configuration is *not* copied into the + * shadowJar. + */ + shadow "org.elasticsearch:elasticsearch:${version}" + shadow "org.elasticsearch.client:elasticsearch-rest-client:${version}" + shadow "org.elasticsearch.plugin:parent-join-client:${version}" + shadow "org.elasticsearch.plugin:aggs-matrix-stats-client:${version}" + shadow "org.elasticsearch.plugin:rank-eval-client:${version}" + shadow "org.elasticsearch.plugin:lang-mustache-client:${version}" + compile project(':x-pack:protocol') testCompile "org.elasticsearch.client:test:${version}" testCompile "org.elasticsearch.test:framework:${version}" @@ -83,9 +98,25 @@ forbiddenApisMain { signaturesURLs += [file('src/main/resources/forbidden/rest-high-level-signatures.txt').toURI().toURL()] } +shadowJar { + classifier = null + mergeServiceFiles() +} + +// We don't need normal jar, we use shadow jar instead +jar.enabled = false + +artifacts { + archives shadowJar +} +assemble.dependsOn shadowJar + javadoc { - // Bundle javadoc from all bundled projects into this project's javadoc - configurations.bundled.dependencies.all { Dependency dep -> + /* + * Bundle all of the javadoc from all of the shaded projects into this one + * so we don't *have* to publish javadoc for all of the "client" jars. + */ + configurations.compile.dependencies.all { Dependency dep -> Project p = dependencyToProject(dep) if (p != null) { evaluationDependsOn(p.path) @@ -93,21 +124,25 @@ javadoc { } } } -jar { - from({configurations.bundled.collect { it.isDirectory() ? it : zipTree(it) }}) { - exclude 'META-INF/*' - } -} + /* * Use the jar for testing so we have tests of the bundled jar. + * Use the "shadow" configuration for testing because we need things + * in it. */ test { classpath -= compileJava.outputs.files - classpath += jar.outputs.files - dependsOn jar + classpath -= configurations.compile + classpath -= configurations.runtime + classpath += configurations.shadow + classpath += shadowJar.outputs.files + dependsOn shadowJar } integTestRunner { classpath -= compileJava.outputs.files - classpath += jar.outputs.files - dependsOn jar + classpath -= configurations.compile + classpath -= configurations.runtime + classpath += configurations.shadow + classpath += shadowJar.outputs.files + dependsOn shadowJar } From 578bf121a19570f12f3195250bc86f64140111c6 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Tue, 10 Jul 2018 12:54:17 -0400 Subject: [PATCH 4/6] Publishing --- client/rest-high-level/build.gradle | 30 +++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/client/rest-high-level/build.gradle b/client/rest-high-level/build.gradle index a9b301a8783b4..ef69aa29a3dfc 100644 --- a/client/rest-high-level/build.gradle +++ b/client/rest-high-level/build.gradle @@ -18,7 +18,8 @@ */ import org.elasticsearch.gradle.precommit.PrecommitTasks -import org.gradle.api.artifacts.ResolvedDependency +import org.gradle.api.XmlProvider +import org.gradle.api.publish.maven.MavenPublication buildscript { repositories { @@ -42,8 +43,29 @@ archivesBaseName = 'elasticsearch-rest-high-level-client' publishing { publications { - nebula { + println("ASDFA now!") + nebula(MavenPublication) { + artifact shadowJar artifactId = archivesBaseName + /* + * Configure the pom to include the "shadow" as compile dependencies + * because that is how we're using them but remove all other dependencies + * because they've been shaded into the jar. + */ + pom.withXml { XmlProvider xml -> + Node root = xml.asNode() + root.remove(root.dependencies) + Node dependenciesNode = root.appendNode('dependencies') + project.configurations.shadow.allDependencies.each { + if (false == it instanceof SelfResolvingDependency) { + Node dependencyNode = dependenciesNode.appendNode('dependency') + dependencyNode.appendNode('groupId', it.group) + dependencyNode.appendNode('artifactId', it.name) + dependencyNode.appendNode('version', it.version) + dependencyNode.appendNode('scope', 'compile') + } + } + } } } } @@ -105,10 +127,6 @@ shadowJar { // We don't need normal jar, we use shadow jar instead jar.enabled = false - -artifacts { - archives shadowJar -} assemble.dependsOn shadowJar javadoc { From 4786607399c167ad5905aab7f2a679216a6aee9d Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Tue, 10 Jul 2018 12:55:05 -0400 Subject: [PATCH 5/6] no more println --- client/rest-high-level/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/client/rest-high-level/build.gradle b/client/rest-high-level/build.gradle index ef69aa29a3dfc..451452759f507 100644 --- a/client/rest-high-level/build.gradle +++ b/client/rest-high-level/build.gradle @@ -43,7 +43,6 @@ archivesBaseName = 'elasticsearch-rest-high-level-client' publishing { publications { - println("ASDFA now!") nebula(MavenPublication) { artifact shadowJar artifactId = archivesBaseName From 33fef73cbf2a06db14117824207a7c3c58e10179 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Tue, 10 Jul 2018 14:07:20 -0400 Subject: [PATCH 6/6] Use the shadow configuration Fixes jarhell! --- qa/ccs-unavailable-clusters/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qa/ccs-unavailable-clusters/build.gradle b/qa/ccs-unavailable-clusters/build.gradle index 86d0cb64f65a2..d9de422bb43e1 100644 --- a/qa/ccs-unavailable-clusters/build.gradle +++ b/qa/ccs-unavailable-clusters/build.gradle @@ -21,5 +21,5 @@ apply plugin: 'elasticsearch.rest-test' apply plugin: 'elasticsearch.test-with-dependencies' dependencies { - testCompile project(path: ':client:rest-high-level', configuration: 'runtime') -} \ No newline at end of file + testCompile project(path: ':client:rest-high-level', configuration: 'shadow') +}