Skip to content

Commit 01140a3

Browse files
authored
SQL: Make a single JDBC driver jar (#31012)
Replaces zip archive containing multiple jars with a single JDBC driver jar that shades all external dependencies. Closes #29856
1 parent e467e67 commit 01140a3

File tree

2 files changed

+62
-69
lines changed

2 files changed

+62
-69
lines changed

x-pack/plugin/sql/jdbc/build.gradle

+58-67
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,40 @@
1+
2+
buildscript {
3+
repositories {
4+
maven {
5+
url 'https://plugins.gradle.org/m2/'
6+
}
7+
}
8+
dependencies {
9+
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.2'
10+
}
11+
}
12+
113
apply plugin: 'elasticsearch.build'
214
apply plugin: 'nebula.maven-base-publish'
315
apply plugin: 'nebula.maven-scm'
16+
apply plugin: 'com.github.johnrengelman.shadow'
417

518
description = 'JDBC driver for Elasticsearch'
19+
archivesBaseName = "x-pack-sql-jdbc"
620

721
forbiddenApisMain {
822
// does not depend on core, so only jdk and http signatures should be checked
923
signaturesURLs = [this.class.getResource('/forbidden/jdk-signatures.txt')]
1024
}
1125

12-
/*
13-
* Bundle as many of our dependencies as we can get away with into the jar.
14-
* We can't currently bundle *all* dependencies into the jar, but we'd like
15-
* to avoid publishing the sql shared libraries if possible. This allows that.
16-
*
17-
* It is possible to use configure this bundling in a bunch of different ways
18-
* but this particular way generates a pom that doesn't declare the bundled
19-
* dependencies as dependencies. Which is a good thing because we don't publish
20-
* them and we don't want consumers to get two copies of them.
21-
*
22-
* We'd *like* to shade these dependencies, at least ones like jackson which we
23-
* know that we can't remove entirely. But for now something like this is
24-
* simpler.
25-
*/
26-
configurations {
27-
bundled
28-
}
29-
sourceSets {
30-
main {
31-
compileClasspath += configurations.bundled
32-
}
33-
test {
34-
compileClasspath += configurations.bundled
35-
}
36-
}
37-
javadoc {
38-
classpath += configurations.bundled
39-
}
40-
jar {
41-
from({configurations.bundled.collect { it.isDirectory() ? it : zipTree(it) }}) {
42-
// We don't need the META-INF from the things we bundle. For now.
43-
exclude 'META-INF/*'
44-
}
45-
}
46-
4726
dependencies {
48-
49-
// Eclipse doesn't know how to deal with these bundled deependencies so make them compile
50-
// dependencies if we are running in Eclipse
51-
if (isEclipse) {
52-
compile (xpackProject('plugin:sql:sql-shared-client')) {
53-
transitive = false
54-
}
55-
compile (xpackProject('plugin:sql:sql-shared-proto')) {
56-
transitive = false
57-
}
58-
} else {
59-
bundled (xpackProject('plugin:sql:sql-shared-client')) {
60-
transitive = false
61-
}
62-
bundled (xpackProject('plugin:sql:sql-shared-proto')) {
63-
transitive = false
64-
}
27+
compile (xpackProject('plugin:sql:sql-shared-client')) {
28+
transitive = false
29+
}
30+
compile (xpackProject('plugin:sql:sql-shared-proto')) {
31+
transitive = false
6532
}
6633
compile (project(':libs:x-content')) {
6734
transitive = false
6835
}
6936
compile project(':libs:core')
7037
runtime "com.fasterxml.jackson.core:jackson-core:${versions.jackson}"
71-
7238
testCompile "org.elasticsearch.test:framework:${version}"
7339
}
7440

@@ -82,23 +48,48 @@ dependencyLicenses {
8248
ignoreSha 'elasticsearch'
8349
}
8450

85-
/*
86-
* Temporary zip file to make the jdbc driver more usable during the 6.3
87-
* release. We'd like to remove this in future releases when the jdbc driver
88-
* bundles or shades all of its dependencies. But for now this should help
89-
* non-maven jdbc users, specifically those folks using BI tools.
90-
*/
91-
task zipWithDependencies(type: Zip) {
92-
from configurations.runtime
93-
from configurations.runtime.artifacts.files
94-
baseName 'elasticsearch-jdbc-with-dependencies'
95-
into "elasticsearch-jdbc-with-dependencies-$version"
51+
shadowJar {
52+
classifier = null
53+
relocate 'com.fasterxml', 'org.elasticsearch.fasterxml'
54+
}
55+
56+
// We don't need normal jar, we use shadow jar instead
57+
jar.enabled = false
58+
59+
// We need a no-depenencies jar though for qa testing so it doesn't conflict with cli
60+
configurations {
61+
nodeps
62+
}
63+
64+
task nodepsJar(type: Jar) {
65+
appendix 'nodeps'
66+
from sourceSets.main.output
9667
}
97-
assemble.dependsOn zipWithDependencies
68+
69+
artifacts {
70+
nodeps nodepsJar
71+
archives shadowJar
72+
}
73+
74+
publishing {
75+
publications {
76+
nebula(MavenPublication) {
77+
artifact shadowJar
78+
pom.withXml {
79+
// Nebula is mistakenly including all dependencies that are already shadowed into the shadow jar
80+
asNode().remove(asNode().dependencies)
81+
}
82+
}
83+
}
84+
}
85+
86+
assemble.dependsOn shadowJar
9887

9988
// Use the jar for testing so the tests are more "real"
10089
test {
10190
classpath -= compileJava.outputs.files
102-
classpath += jar.outputs.files
103-
dependsOn jar
91+
classpath -= configurations.compile
92+
classpath -= configurations.runtime
93+
classpath += shadowJar.outputs.files
94+
dependsOn shadowJar
10495
}

x-pack/qa/sql/build.gradle

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies {
99
compile "org.elasticsearch.test:framework:${version}"
1010

1111
// JDBC testing dependencies
12-
compile xpackProject('plugin:sql:jdbc')
12+
compile project(path: xpackModule('sql:jdbc'), configuration: 'nodeps')
1313
compile "net.sourceforge.csvjdbc:csvjdbc:1.0.34"
1414

1515
// CLI testing dependencies
@@ -87,7 +87,9 @@ subprojects {
8787
// JDBC testing dependencies
8888
testRuntime "net.sourceforge.csvjdbc:csvjdbc:1.0.34"
8989
testRuntime "com.h2database:h2:1.4.197"
90-
testRuntime xpackProject('plugin:sql:jdbc')
90+
testRuntime project(path: xpackModule('sql:jdbc'), configuration: 'nodeps')
91+
testRuntime xpackProject('plugin:sql:sql-shared-client')
92+
9193

9294
// TODO check if needed
9395
testRuntime("org.antlr:antlr4-runtime:4.5.3") {

0 commit comments

Comments
 (0)