1
- import org.elasticsearch.gradle.precommit.PrecommitTasks
2
-
3
1
/*
4
2
* Licensed to Elasticsearch under one or more contributor
5
3
* license agreements. See the NOTICE file distributed with
@@ -18,30 +16,86 @@ import org.elasticsearch.gradle.precommit.PrecommitTasks
18
16
* specific language governing permissions and limitations
19
17
* under the License.
20
18
*/
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
+
21
35
apply plugin : ' elasticsearch.build'
22
36
apply plugin : ' elasticsearch.rest-test'
23
37
apply plugin : ' nebula.maven-base-publish'
24
38
apply plugin : ' nebula.maven-scm'
39
+ apply plugin : ' com.github.johnrengelman.shadow'
25
40
26
41
group = ' org.elasticsearch.client'
27
42
archivesBaseName = ' elasticsearch-rest-high-level-client'
28
43
29
44
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
+ }
33
66
}
67
+ }
34
68
}
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
+ }
35
85
}
36
86
37
87
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' )
45
99
46
100
testCompile " org.elasticsearch.client:test:${ version} "
47
101
testCompile " org.elasticsearch.test:framework:${ version} "
@@ -64,3 +118,48 @@ forbiddenApisMain {
64
118
signaturesURLs + = [PrecommitTasks . getResource(' /forbidden/http-signatures.txt' )]
65
119
signaturesURLs + = [file(' src/main/resources/forbidden/rest-high-level-signatures.txt' ). toURI(). toURL()]
66
120
}
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
+ }
0 commit comments