Skip to content

Commit 4d83a0d

Browse files
authored
HLREST: Bundle the x-pack protocol project (#31904)
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
1 parent 25cd835 commit 4d83a0d

File tree

2 files changed

+113
-14
lines changed

2 files changed

+113
-14
lines changed

client/rest-high-level/build.gradle

+111-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import org.elasticsearch.gradle.precommit.PrecommitTasks
2-
31
/*
42
* Licensed to Elasticsearch under one or more contributor
53
* license agreements. See the NOTICE file distributed with
@@ -18,30 +16,86 @@ import org.elasticsearch.gradle.precommit.PrecommitTasks
1816
* specific language governing permissions and limitations
1917
* under the License.
2018
*/
19+
20+
import org.elasticsearch.gradle.precommit.PrecommitTasks
21+
import org.gradle.api.XmlProvider
22+
import org.gradle.api.publish.maven.MavenPublication
23+
24+
buildscript {
25+
repositories {
26+
maven {
27+
url 'https://plugins.gradle.org/m2/'
28+
}
29+
}
30+
dependencies {
31+
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
32+
}
33+
}
34+
2135
apply plugin: 'elasticsearch.build'
2236
apply plugin: 'elasticsearch.rest-test'
2337
apply plugin: 'nebula.maven-base-publish'
2438
apply plugin: 'nebula.maven-scm'
39+
apply plugin: 'com.github.johnrengelman.shadow'
2540

2641
group = 'org.elasticsearch.client'
2742
archivesBaseName = 'elasticsearch-rest-high-level-client'
2843

2944
publishing {
30-
publications {
31-
nebula {
32-
artifactId = archivesBaseName
45+
publications {
46+
nebula(MavenPublication) {
47+
artifact shadowJar
48+
artifactId = archivesBaseName
49+
/*
50+
* Configure the pom to include the "shadow" as compile dependencies
51+
* because that is how we're using them but remove all other dependencies
52+
* because they've been shaded into the jar.
53+
*/
54+
pom.withXml { XmlProvider xml ->
55+
Node root = xml.asNode()
56+
root.remove(root.dependencies)
57+
Node dependenciesNode = root.appendNode('dependencies')
58+
project.configurations.shadow.allDependencies.each {
59+
if (false == it instanceof SelfResolvingDependency) {
60+
Node dependencyNode = dependenciesNode.appendNode('dependency')
61+
dependencyNode.appendNode('groupId', it.group)
62+
dependencyNode.appendNode('artifactId', it.name)
63+
dependencyNode.appendNode('version', it.version)
64+
dependencyNode.appendNode('scope', 'compile')
65+
}
3366
}
67+
}
3468
}
69+
}
70+
}
71+
72+
/*
73+
* We need somewhere to configure dependencies that we don't wish to shade
74+
* into the high level REST client. The shadow plugin creates a "shadow"
75+
* configuration which is *almost* exactly that. It is never bundled into
76+
* the shaded jar but is used for main source compilation. Unfortunately,
77+
* by default it is not used for *test* source compilation and isn't used
78+
* in tests at all. This change makes it available for test compilation.
79+
* A change below makes it available for testing.
80+
*/
81+
sourceSets {
82+
test {
83+
compileClasspath += configurations.shadow
84+
}
3585
}
3686

3787
dependencies {
38-
compile "org.elasticsearch:elasticsearch:${version}"
39-
compile "org.elasticsearch.client:elasticsearch-rest-client:${version}"
40-
compile "org.elasticsearch.plugin:parent-join-client:${version}"
41-
compile "org.elasticsearch.plugin:aggs-matrix-stats-client:${version}"
42-
compile "org.elasticsearch.plugin:rank-eval-client:${version}"
43-
compile "org.elasticsearch.plugin:lang-mustache-client:${version}"
44-
compile project(':x-pack:protocol') // TODO bundle into the jar
88+
/*
89+
* Everything in the "shadow" configuration is *not* copied into the
90+
* shadowJar.
91+
*/
92+
shadow "org.elasticsearch:elasticsearch:${version}"
93+
shadow "org.elasticsearch.client:elasticsearch-rest-client:${version}"
94+
shadow "org.elasticsearch.plugin:parent-join-client:${version}"
95+
shadow "org.elasticsearch.plugin:aggs-matrix-stats-client:${version}"
96+
shadow "org.elasticsearch.plugin:rank-eval-client:${version}"
97+
shadow "org.elasticsearch.plugin:lang-mustache-client:${version}"
98+
compile project(':x-pack:protocol')
4599

46100
testCompile "org.elasticsearch.client:test:${version}"
47101
testCompile "org.elasticsearch.test:framework:${version}"
@@ -64,3 +118,48 @@ forbiddenApisMain {
64118
signaturesURLs += [PrecommitTasks.getResource('/forbidden/http-signatures.txt')]
65119
signaturesURLs += [file('src/main/resources/forbidden/rest-high-level-signatures.txt').toURI().toURL()]
66120
}
121+
122+
shadowJar {
123+
classifier = null
124+
mergeServiceFiles()
125+
}
126+
127+
// We don't need normal jar, we use shadow jar instead
128+
jar.enabled = false
129+
assemble.dependsOn shadowJar
130+
131+
javadoc {
132+
/*
133+
* Bundle all of the javadoc from all of the shaded projects into this one
134+
* so we don't *have* to publish javadoc for all of the "client" jars.
135+
*/
136+
configurations.compile.dependencies.all { Dependency dep ->
137+
Project p = dependencyToProject(dep)
138+
if (p != null) {
139+
evaluationDependsOn(p.path)
140+
source += p.sourceSets.main.allJava
141+
}
142+
}
143+
}
144+
145+
/*
146+
* Use the jar for testing so we have tests of the bundled jar.
147+
* Use the "shadow" configuration for testing because we need things
148+
* in it.
149+
*/
150+
test {
151+
classpath -= compileJava.outputs.files
152+
classpath -= configurations.compile
153+
classpath -= configurations.runtime
154+
classpath += configurations.shadow
155+
classpath += shadowJar.outputs.files
156+
dependsOn shadowJar
157+
}
158+
integTestRunner {
159+
classpath -= compileJava.outputs.files
160+
classpath -= configurations.compile
161+
classpath -= configurations.runtime
162+
classpath += configurations.shadow
163+
classpath += shadowJar.outputs.files
164+
dependsOn shadowJar
165+
}

qa/ccs-unavailable-clusters/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ apply plugin: 'elasticsearch.rest-test'
2121
apply plugin: 'elasticsearch.test-with-dependencies'
2222

2323
dependencies {
24-
testCompile project(path: ':client:rest-high-level', configuration: 'runtime')
25-
}
24+
testCompile project(path: ':client:rest-high-level', configuration: 'shadow')
25+
}

0 commit comments

Comments
 (0)