-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
208 lines (182 loc) · 8.9 KB
/
Copy pathbuild.gradle
File metadata and controls
208 lines (182 loc) · 8.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
plugins {
id "maven-publish"
id "java-library"
id "io.freefair.lombok" version "8.6"
id "signing"
id "io.github.gradle-nexus.publish-plugin" version "1.3.0"
id 'com.vanniktech.maven.publish' version '0.30.0'
id 'com.gradleup.shadow' version '8.3.5'
}
group 'ai.chalk'
version = project.hasProperty("version") ? project.getProperty("version") : "0.0.0"
repositories {
mavenCentral()
}
def versions = [
grpcVersion: '1.64.0',
arrowVersion: '17.0.0',
jacksonVersion: '2.15.2',
protobufVersion: '3.25.1',
flinkVersion: '1.19.2'
]
dependencies {
api "com.fasterxml.jackson.core:jackson-databind:${versions.jacksonVersion}"
api "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${versions.jacksonVersion}"
api "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${versions.jacksonVersion}"
api "com.google.protobuf:protobuf-java:${versions.protobufVersion}"
api "io.grpc:grpc-core:${versions.grpcVersion}"
api "io.grpc:grpc-protobuf:${versions.grpcVersion}"
api "io.grpc:grpc-stub:${versions.grpcVersion}"
api "io.grpc:grpc-netty-shaded:${versions.grpcVersion}"
api "org.apache.arrow:arrow-compression:${versions.arrowVersion}"
api "org.apache.arrow:arrow-memory-netty:${versions.arrowVersion}"
api "org.apache.arrow:arrow-vector:${versions.arrowVersion}"
implementation 'javax.annotation:javax.annotation-api:1.3.2'
// Flink connector (ai.chalk.flink.*). compileOnly => not bundled and NOT exposed transitively,
// so plain chalk-java users get no Flink in their tree; the classes only resolve for callers who
// already run Flink. slf4j-api likewise comes from the Flink runtime at execution time.
compileOnly "org.apache.flink:flink-streaming-java:${versions.flinkVersion}"
compileOnly "org.apache.flink:flink-core:${versions.flinkVersion}"
compileOnly 'org.slf4j:slf4j-api:2.0.9'
testImplementation 'org.junit.jupiter:junit-jupiter:5.7.0'
testImplementation 'org.slf4j:slf4j-simple:2.0.9'
}
// Self-contained "shaded" jar: relocates ALL third-party deps into ai.chalk.shaded.* so the artifact
// is immune to whatever versions a consumer (or their Flink runtime) pins. Flink is compileOnly, so
// it is not bundled (stays provided by the cluster). Publish as the `shaded` classifier.
shadowJar {
archiveClassifier = 'shaded'
mergeServiceFiles() // rewrite META-INF/services (grpc providers, jackson, etc.) to shaded names
// slf4j-api is the logging facade — let the runtime (Flink) own it exclusively, so there's no
// facade version skew (1.x vs 2.x binding). chalk-java's org.slf4j refs bind to the runtime's.
dependencies { exclude(dependency('org.slf4j:slf4j-api')) }
relocate 'com.google', 'ai.chalk.shaded.google' // protobuf, guava, gson, flatbuffers, api-protos
relocate 'io.grpc', 'ai.chalk.shaded.grpc' // incl. grpc-netty-shaded
relocate 'io.netty', 'ai.chalk.shaded.netty' // arrow-memory-netty (pure JVM here)
relocate 'io.perfmark', 'ai.chalk.shaded.perfmark'
relocate 'com.fasterxml.jackson', 'ai.chalk.shaded.jackson'
relocate 'org.apache.arrow', 'ai.chalk.shaded.arrow'
relocate 'org.apache.commons', 'ai.chalk.shaded.commons' // codec, io, compress, lang3
relocate 'org.yaml.snakeyaml', 'ai.chalk.shaded.snakeyaml'
relocate 'org.checkerframework', 'ai.chalk.shaded.checkerframework'
relocate 'org.codehaus.mojo', 'ai.chalk.shaded.mojo'
// Intentionally NOT relocated:
// ai.chalk.* -> the public API (consumers import these)
// org.slf4j -> logging facade; must bind to the runtime's logging
// javax.annotation -> standard annotations, no conflict
// com.github.luben -> zstd-jni: native JNI, relocating its package breaks the .so binding
// org.apache.flink.* -> provided by the cluster (compileOnly, not bundled)
}
test {
useJUnitPlatform()
jvmArgs '--add-opens=java.base/java.nio=ALL-UNNAMED'
testLogging {
// Ensure that the standard output from the tests is shown in CI logs
showStandardStreams = true
events "passed", "skipped", "failed"
}
}
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
def configurePom = { pom ->
pom.name = 'Chalk Java'
pom.description = 'The Java client for Chalk'
pom.url = 'https://github.com/chalk-ai/chalk-java'
pom.licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
pom.developers {
developer {
id = 'chalk-ai'
name = 'Chalk'
email = 'support@chalk.ai'
}
}
pom.scm {
connection = 'scm:git:git://github.com/chalk-ai/chalk-java.git'
developerConnection = 'scm:git:ssh://github.com:chalk-ai/chalk-java.git'
url = 'https://github.com/chalk-ai/chalk-java/'
}
}
import com.vanniktech.maven.publish.SonatypeHost
mavenPublishing {
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, true)
signAllPublications()
coordinates(project.group.toString(), project.name, project.version.toString())
pom {
name = 'Chalk Java'
description = 'The Java client for Chalk'
url = 'https://github.com/chalk-ai/chalk-java'
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'chalk-ai'
name = 'Chalk'
email = 'support@chalk.ai'
}
}
scm {
connection = 'scm:git:git://github.com/chalk-ai/chalk-java.git'
developerConnection = 'scm:git:ssh://github.com:chalk-ai/chalk-java.git'
url = 'https://github.com/chalk-ai/chalk-java/'
}
}
}
// Second coordinate: ai.chalk:chalk-java-shaded. Identical classes to chalk-java, but every
// third-party dependency is relocated into ai.chalk.shaded.* (see the shadowJar block). Its POM
// declares only slf4j-api (a non-relocatable logging facade) — every other dep lives inside the jar,
// so a consumer pinned to older protobuf/grpc/jackson/arrow/netty never gets a conflicting transitive
// pulled in. Built as a manual publication (not `from components.java`) to keep the POM minimal.
publishing {
publications {
shaded(MavenPublication) {
artifactId = 'chalk-java-shaded'
// Publish the shaded jar as the module's main artifact (strip the 'shaded' classifier).
artifact(tasks.shadowJar) { classifier = null }
// POM name/license/scm/developers are applied to all publications by the vanniktech
// mavenPublishing block below. The ONLY declared dependency is slf4j-api: bundled
// arrow/netty classes reference org.slf4j, but it is not relocatable (it's a logging
// facade that must bind to the runtime's logging). Declaring it guarantees the class is
// present for any consumer; in a Flink runtime, Flink parent-first-loads org.slf4j, so
// its own version always wins regardless of what we declare. Everything else is bundled +
// relocated inside the jar, so no other (conflict-prone) dependency is declared.
pom.withXml {
def deps = asNode().appendNode('dependencies')
def slf4j = deps.appendNode('dependency')
slf4j.appendNode('groupId', 'org.slf4j')
slf4j.appendNode('artifactId', 'slf4j-api')
slf4j.appendNode('version', '2.0.9')
slf4j.appendNode('scope', 'runtime')
}
}
}
}
// Central rejects any component missing sources/javadoc, and one bad component fails the whole
// deployment bundle — which would take chalk-java down with it. Reuse the unshaded jars: relocation
// is a bytecode rewrite, so the sources are identical and the public ai.chalk.* API is unrelocated.
// Deferred to afterEvaluate because the vanniktech plugin registers both tasks after this file runs.
afterEvaluate {
publishing.publications.named('shaded') {
artifact(tasks.named('sourcesJar')) { classifier = 'sources' }
artifact(tasks.named('mavenPlainJavadocJar')) { classifier = 'javadoc' }
}
}
// With two publications (maven + shaded), both sign tasks write their .asc into build/libs, and each
// publish task reads from build/libs — so Gradle's strict validation flags an implicit dependency
// between publish and the *other* publication's sign task and fails the build. Order all publish
// tasks after all sign tasks to make the dependency explicit.
import org.gradle.api.publish.maven.tasks.AbstractPublishToMaven
import org.gradle.plugins.signing.Sign
tasks.withType(AbstractPublishToMaven).configureEach {
mustRunAfter(tasks.withType(Sign))
}