OpenSearch/sql/jdbc/build.gradle
Nik Everett 89e80e0cba Teach SQL to parse Elasticsearch's standard error responses (elastic/x-pack-elasticsearch#2764)
This teaches SQL to parse Elasticsearch's standard error responses
but doesn't change SQL to general Elasticsearch's standard error responses
in all cases. That can come in a followup. We do this parsing with
jackson-core, the same dependency Elasticsearch uses for parsing
json. We shade jackson-core in the JDBC driver so that users don't have to worry about
dependency clashes. We do not do so in the CLI because it is a standalone
application.

We get a few "bonus" changes along the way:
1. We save a copy operation. Before this change responses were spooled
into memory and then parsed. After this change they are parsed directly
from the response stream.
2. We had a few classes entirely to support the spooling operation that we
no longer need: `BytesArray`, `FastByteArrayInputStream`, and
`BasicByteArrayOutputStream`.
3. SQL's `Version` was incorrectly parsing the version from the jar manifest.
We didn't notice because the test was rigged to return `UNKNOWN` because
we *were* running the test from the compiled classes directory instead of the
jar. As part of shading jackson we moved running the tests to running against
the shaded jar. Now we can actually assert that we parse the version correctly.
It turns out we weren't. So I fixed it.

Original commit: elastic/x-pack-elasticsearch@2e8f397bf4
2017-11-14 21:31:35 -05:00

65 lines
2.0 KiB
Groovy

plugins {
id 'com.github.johnrengelman.shadow' version '2.0.1'
}
import org.elasticsearch.gradle.test.RunTask
description = 'JDBC driver for Elasticsearch'
forbiddenApisMain {
// does not depend on core, so only jdk and http signatures should be checked
signaturesURLs = [this.class.getResource('/forbidden/jdk-signatures.txt')]
}
dependencies {
compile project(':x-pack-elasticsearch:sql:shared-client')
compile project(':x-pack-elasticsearch:sql:jdbc-proto')
compile project(':x-pack-elasticsearch:sql:shared-proto')
runtime "com.fasterxml.jackson.core:jackson-core:${versions.jackson}"
/* We want to limit these dependencies so we don't have a huge jar.
* Since we shadow these dependencies we don't have to be super careful
* but we have to be *somewhat* careful because things like commons logging
* don't shadow properly. */
}
dependencyLicenses {
mapping from: /jdbc-proto.*/, to: 'elasticsearch'
mapping from: /shared-client.*/, to: 'elasticsearch'
mapping from: /shared-proto.*/, to: 'elasticsearch'
mapping from: /jackson-.*/, to: 'jackson'
ignoreSha 'jdbc-proto'
ignoreSha 'shared-client'
ignoreSha 'shared-proto'
}
/* Disable the jar task configured by the java plugin. We're not going to
* distribute an unshaded jar so there is no need making one. */
jar {
enabled = false
}
configurations.archives.artifacts.removeAll { it.archiveTask.is jar }
/* Move the shaded jar to the empty classifier because it is the only one
* we're shipping. */
shadowJar {
classifier = null
// We only need to relocate jackson
relocate 'com.fasterxml.jackson', 'org.elasticsearch.xpack.sql.jdbc.shadow.jacksonp'
manifest {
inheritFrom jar.manifest
}
}
assemble.dependsOn shadowJar
artifacts {
archives shadowJar
}
// And for better realism let's use the shaded jar for testing
test {
classpath -= compileJava.outputs.files
classpath -= configurations.compile
classpath -= configurations.runtime
classpath += shadowJar.outputs.files
dependsOn shadowJar
}