Repository navigation
Expand file tree
/
Copy pathbuild.gradle
More file actions
478 lines (422 loc) · 22.3 KB
/
Copy pathbuild.gradle
File metadata and controls
478 lines (422 loc) · 22.3 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
plugins {
id 'io.kestra.gradle.repository-conventions' version '1.2.12'
id "io.kestra.gradle.plugin-doc-lint" version '1.2.12'
id 'io.kestra.gradle.spotless-conventions' version '1.2.12'
id 'java-library'
id "idea"
id 'jacoco'
id "com.gradleup.shadow" version "9.6.1"
id 'signing'
id 'net.researchgate.release' version '3.2.0'
id "com.vanniktech.maven.publish" version "0.37.0"
id "io.kestra.gradle.inject-bom-versions" version '1.2.12'
id 'com.github.node-gradle.node' version '7.1.0'
}
def isBuildSnapshot = version.toString().endsWith("-SNAPSHOT")
def langchain4jVersion = "1.22.0"
def langchain4jBetaVersion = "1.22.0-beta32"
repositories {
mavenLocal()
mavenCentral()
if (isBuildSnapshot) {
maven { url "https://central.sonatype.com/repository/maven-snapshots/" }
}
}
final targetJavaVersion = JavaVersion.VERSION_25
java {
sourceCompatibility = targetJavaVersion
targetCompatibility = targetJavaVersion
}
group "io.kestra.plugin"
description 'Plugin for AI with Langchain4j for Kestra'
tasks.withType(JavaCompile).configureEach {
options.encoding = "UTF-8"
options.compilerArgs.add("-parameters")
}
// Security: the platform BOM pins Jackson 2.22.1, affected by the databind and core advisories. Force the patched
// release until the platform ships it. Jackson 2 is enforced by enforcedPlatform, so a strict constraint conflicts.
configurations.configureEach {
resolutionStrategy.force 'com.fasterxml.jackson.core:jackson-databind:2.22.3',
'com.fasterxml.jackson.core:jackson-core:2.22.3'
// SEC-0369: platform BOM pins guava 33.7.1-jre, remove once it ships >= 33.7.2.
resolutionStrategy.force 'com.google.guava:guava:33.7.2-jre'
}
dependencies {
// Platform: Langchain4J libraries are defines inside it
annotationProcessor enforcedPlatform("io.kestra:platform:$kestraVersion")
implementation enforcedPlatform("io.kestra:platform:$kestraVersion")
// lombok
annotationProcessor "org.projectlombok:lombok"
compileOnly "org.projectlombok:lombok"
// kestra
annotationProcessor group: "io.kestra", name: "processor", version: kestraVersion
compileOnly group: "io.kestra", name: "core", version: kestraVersion
compileOnly group: "io.kestra", name: "script", version: kestraVersion
implementation "io.kestra:kestra-api-client:2.0.3"
// compileOnly as it comes from Kestra script library
compileOnly('com.github.docker-java:docker-java') {
exclude group: 'com.github.docker-java', module: 'docker-java-transport-netty'
exclude group: 'com.github.docker-java', module: 'docker-java-transport-jersey'
}
compileOnly 'com.github.docker-java:docker-java-transport-httpclient5'
// Shared GCP authentication (same behavior as plugin-gcp)
implementation 'io.kestra.plugin:plugin-gcp-lib:1.1.1'
// Langchain4j model providers (stable)
implementation "dev.langchain4j:langchain4j:${langchain4jVersion}"
implementation "dev.langchain4j:langchain4j-anthropic:${langchain4jVersion}"
implementation "dev.langchain4j:langchain4j-azure-open-ai:${langchain4jVersion}"
implementation "dev.langchain4j:langchain4j-bedrock:${langchain4jVersion}"
implementation "dev.langchain4j:langchain4j-google-ai-gemini:${langchain4jVersion}"
implementation "dev.langchain4j:langchain4j-mistral-ai:${langchain4jVersion}"
implementation "dev.langchain4j:langchain4j-ollama:${langchain4jVersion}"
implementation "dev.langchain4j:langchain4j-open-ai:${langchain4jVersion}"
// Langchain4j model providers (beta)
implementation "dev.langchain4j:langchain4j-vertex-ai:${langchain4jBetaVersion}"
implementation "dev.langchain4j:langchain4j-google-genai:${langchain4jBetaVersion}"
implementation "dev.langchain4j:langchain4j-workers-ai:${langchain4jBetaVersion}"
implementation "dev.langchain4j:langchain4j-local-ai:${langchain4jBetaVersion}"
implementation "dev.langchain4j:langchain4j-community-oci-genai:${langchain4jBetaVersion}"
// HTTP client of the OCI SDK (without it the OCI client cannot be created): same version as oci-java-sdk-common, see components below
implementation "com.oracle.oci.sdk:oci-java-sdk-common-httpclient-jersey3"
implementation "dev.langchain4j:langchain4j-mariadb:${langchain4jBetaVersion}"
implementation "dev.langchain4j:langchain4j-tablestore:${langchain4jBetaVersion}"
implementation "dev.langchain4j:langchain4j-community-dashscope:${langchain4jBetaVersion}"
implementation "dev.langchain4j:langchain4j-community-zhipu-ai:${langchain4jBetaVersion}"
implementation "dev.langchain4j:langchain4j-watsonx:${langchain4jBetaVersion}"
implementation('org.bouncycastle:bcpkix-jdk18on') // for PEM
implementation "org.apache.tika:tika-core:4.1.0"
implementation "dev.langchain4j:langchain4j-code-execution-engine-judge0:${langchain4jBetaVersion}"
// Langchain4j embeddings stores
implementation "dev.langchain4j:langchain4j-chroma:${langchain4jBetaVersion}"
implementation "dev.langchain4j:langchain4j-elasticsearch:${langchain4jBetaVersion}"
implementation "dev.langchain4j:langchain4j-mongodb-atlas:${langchain4jBetaVersion}"
implementation "dev.langchain4j:langchain4j-milvus:${langchain4jBetaVersion}"
implementation "dev.langchain4j:langchain4j-pinecone:${langchain4jBetaVersion}"
implementation "dev.langchain4j:langchain4j-pgvector:${langchain4jBetaVersion}"
implementation "dev.langchain4j:langchain4j-community-redis:${langchain4jBetaVersion}"
implementation "dev.langchain4j:langchain4j-qdrant:${langchain4jBetaVersion}"
implementation "dev.langchain4j:langchain4j-weaviate:${langchain4jBetaVersion}"
// tools
implementation "dev.langchain4j:langchain4j-web-search-engine-google-custom:${langchain4jBetaVersion}"
implementation "dev.langchain4j:langchain4j-web-search-engine-tavily:${langchain4jBetaVersion}"
implementation "dev.langchain4j:langchain4j-community-web-search-engine-firecrawl:${langchain4jBetaVersion}"
// Pinned below langchain4jBetaVersion: langchain4j-mcp >= 1.19.0-beta29 dropped
// HttpMcpTransport (legacy 2024-11-05 SSE: GET to open the stream, dynamic POST endpoint
// via an "endpoint" SSE event) with no replacement - StreamableHttpMcpTransport only speaks
// the modern Streamable HTTP protocol (direct POST), so it 404s against legacy SSE-only
// servers such as mcp/everything's sse.js.
def langchain4jMcpVersion = "1.13.0-beta23"
implementation "dev.langchain4j:langchain4j-mcp:${langchain4jMcpVersion}"
implementation "dev.langchain4j:langchain4j-mcp-docker:${langchain4jMcpVersion}"
// retrievers
implementation "dev.langchain4j:langchain4j-experimental-sql:${langchain4jBetaVersion}"
// agents
// Pinned below langchain4jBetaVersion: langchain4j-agentic-a2a >= 1.19.0-beta29 pulls
// org.a2aproject.sdk 1.1.0.Final, whose generated grpc classes require a protobuf-java
// version newer than the one Kestra's platform BOM enforces (3.25.8), which lacks the
// RuntimeVersion gencode-check class and breaks A2AClient at runtime with NoClassDefFoundError.
def langchain4jAgenticVersion = "1.22.0-beta32"
implementation "dev.langchain4j:langchain4j-agentic:${langchain4jAgenticVersion}"
implementation "dev.langchain4j:langchain4j-agentic-a2a:${langchain4jAgenticVersion}"
// skills
implementation "dev.langchain4j:langchain4j-skills:${langchain4jBetaVersion}"
// in-process ONNX embeddings (OnnxBertBiEncoder); brings onnxruntime + DJL tokenizers natives
implementation "dev.langchain4j:langchain4j-embeddings:${langchain4jBetaVersion}"
// Security: Jackson 3 resolves at 3.0.0 (runtime) and 3.1.4 (tests); force the patched release
constraints {
implementation('tools.jackson.core:jackson-databind') { version { strictly '3.1.7' } }
implementation('tools.jackson.core:jackson-core') { version { strictly '3.1.7' } }
}
implementation "com.azure:azure-identity" // For Azure OpenAI
implementation "io.opentelemetry:opentelemetry-api"
implementation "io.opentelemetry:opentelemetry-sdk"
implementation "io.opentelemetry:opentelemetry-exporter-otlp"
}
/**********************************************************************************************************************\
* Test
**********************************************************************************************************************/
test {
useJUnitPlatform()
}
dependencies {
// Platform
testAnnotationProcessor enforcedPlatform("io.kestra:platform:$kestraVersion")
testImplementation enforcedPlatform("io.kestra:platform:$kestraVersion")
// lombok
testAnnotationProcessor "org.projectlombok:lombok"
testCompileOnly 'org.projectlombok:lombok'
// micronaut
testAnnotationProcessor "io.micronaut:micronaut-inject-java"
testAnnotationProcessor "io.micronaut.validation:micronaut-validation-processor"
testImplementation "io.micronaut.test:micronaut-test-junit5"
testImplementation "io.micronaut:micronaut-jackson-databind"
// test deps needed only for to have a runner
testAnnotationProcessor group: "io.kestra", name: "processor", version: kestraVersion
testImplementation group: "io.kestra", name: "core", version: kestraVersion
testImplementation group: "io.kestra", name: "tests", version: kestraVersion
testImplementation group: "io.kestra", name: "script", version: kestraVersion
testImplementation group: "io.kestra", name: "repository-memory", version: kestraVersion
testImplementation group: "io.kestra", name: "runner-memory", version: kestraVersion
testImplementation group: "io.kestra", name: "storage-local", version: kestraVersion
// test
testImplementation "org.junit.jupiter:junit-jupiter-engine"
testImplementation "org.hamcrest:hamcrest"
testImplementation "org.hamcrest:hamcrest-library"
testImplementation "org.wiremock:wiremock-jetty12"
// used in KestraTaskTest to exercise a real RunnableTask (log fetching) as an AI tool
testImplementation group: "io.kestra.plugin", name: "plugin-kestra", version: "2.3.1"
testImplementation 'org.testcontainers:testcontainers-ollama:2.0.5'
testImplementation 'org.testcontainers:testcontainers-elasticsearch:2.0.5'
// Embeddings stores
testImplementation "dev.langchain4j:langchain4j-embeddings-all-minilm-l6-v2:${langchain4jBetaVersion}"
testImplementation 'org.testcontainers:testcontainers-chromadb:2.0.5'
testImplementation 'org.testcontainers:testcontainers-milvus:2.0.5'
testImplementation 'org.testcontainers:testcontainers-mongodb:2.0.5'
testImplementation 'org.testcontainers:testcontainers-mariadb:2.0.5'
// Memories
testImplementation "org.testcontainers:testcontainers-postgresql:2.0.5"
}
/**********************************************************************************************************************\
* Allure Reports
**********************************************************************************************************************/
dependencies {
testImplementation enforcedPlatform("io.kestra:platform:$kestraVersion")
testImplementation "io.qameta.allure:allure-junit5"
}
/**********************************************************************************************************************\
* Jacoco
**********************************************************************************************************************/
test {
finalizedBy jacocoTestReport
}
jacocoTestReport {
dependsOn test
reports {
xml.required.set(true)
}
}
/**********************************************************************************************************************\
* Publish
**********************************************************************************************************************/
mavenPublishing {
publishToMavenCentral(true)
signAllPublications()
coordinates("${project.group}", "${rootProject.name}", "${project.version}")
pom {
name = "${project.name}"
description = "${project.group}:${rootProject.name}:${project.version}"
url = "https://github.com/kestra-io/${project.name}"
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'tchiotludo'
name = 'Dehon'
email = 'ldehon@kestra.io'
}
}
scm {
connection = 'scm:git:'
url = "https://github.com/kestra-io/${project.name}"
}
}
}
tasks.withType(GenerateModuleMetadata).configureEach {
// Suppression this validation error as we want to enforce the Kestra platform
suppressedValidationErrors.add('enforced-platform')
}
jar {
manifest {
attributes(
"X-Kestra-Name": project.name,
"X-Kestra-Title": "AI",
"X-Kestra-Group": project.group + ".ai",
"X-Kestra-Description": project.description,
"X-Kestra-Version": project.version
)
}
}
dependencies {
components {
// langchain4j-oci brings the OCI SDK without an HTTP client: keep jersey3 on the same version as the SDK it brings
withModule("com.oracle.oci.sdk:oci-java-sdk-common") {
allVariants {
withDependencies {
add("com.oracle.oci.sdk:oci-java-sdk-common-httpclient-jersey3:${id.version}")
}
}
}
}
}
configurations.runtimeClasspath {
exclude group: "com.azure", module: "azure-core-test"
exclude group: "org.junit.jupiter"
exclude group: "org.junit.platform"
exclude group: "org.apache.ant"
// Jackson is provided by Kestra at runtime and shadowJar below excludes every com/fasterxml/jackson class, but the
// artifacts would still leak their META-INF/services entries into the merged service files. Those entries then point
// at classes the JAR does not contain, ServiceLoader throws "Provider ... not found", and langchain4j's Json can no
// longer initialise, failing every agent tool call (#531).
exclude group: "com.fasterxml.jackson"
exclude group: "com.fasterxml.jackson.core"
exclude group: "com.fasterxml.jackson.dataformat"
exclude group: "com.fasterxml.jackson.datatype"
exclude group: "com.fasterxml.jackson.jaxrs"
exclude group: "com.fasterxml.jackson.module"
}
shadowJar {
archiveClassifier.set(null)
// Shadow 9 defaults to EXCLUDE, which drops duplicate service files before mergeServiceFiles() (lost grpc's dns resolver).
filesMatching("META-INF/services/**") {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
mergeServiceFiles()
zip64 true
minimize {
// avoid to minimize big SDKs (reflection + risky)
exclude(dependency("software.amazon.awssdk:.*"))
exclude(dependency("com.google.cloud:.*"))
exclude(dependency("com.azure:.*"))
exclude(dependency("io.netty:.*"))
exclude(dependency("com.fasterxml.jackson.*:.*"))
exclude(dependency("dev.langchain4j.*:.*"))
// native libraries loaded via JNI/reflection
exclude(dependency("com.microsoft.onnxruntime:.*"))
exclude(dependency("ai.djl.*:.*"))
// HTTP client of the OCI SDK is loaded through ServiceLoader
exclude(dependency("com.oracle.oci.sdk:oci-java-sdk-common-httpclient-jersey3:.*"))
}
exclude "org/slf4j/**"
exclude "ch/qos/logback/**"
exclude "com/fasterxml/jackson/**"
exclude "okhttp3/**"
exclude "okio/**"
exclude "META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA"
exclude "META-INF/INDEX.LIST"
exclude "module-info.class"
// native debug symbols shipped by onnxruntime (~64 MB), never loaded at runtime
exclude "**/*.pdb"
exclude "**/*.dSYM/**"
}
// Guards the service-file merge: checks the OCI SDK HTTP provider is shaded, then loads the jar in isolation and checks grpc's dns resolver and pick_first.
tasks.register("verifyShadedGrpc") {
dependsOn shadowJar
doLast {
def jarFile = shadowJar.archiveFile.get().asFile
// OCI SDK HTTP client is loaded through ServiceLoader: minimize() must not drop it
new java.util.zip.ZipFile(jarFile).withCloseable { zip ->
def provider = "com.oracle.bmc.http.client.jersey3.Jersey3HttpProvider"
def services = zip.getEntry("META-INF/services/com.oracle.bmc.http.client.HttpProvider")
if (zip.getEntry(provider.replace('.', '/') + ".class") == null || services == null
|| !zip.getInputStream(services).text.contains(provider)) {
throw new GradleException("${provider} or its META-INF/services entry is missing from ${jarFile.name} -- OciGenAI cannot create its OCI client.")
}
}
def loader = new URLClassLoader([jarFile.toURI().toURL()] as URL[], ClassLoader.getPlatformClassLoader())
try {
def nameResolverRegistryClass = loader.loadClass("io.grpc.NameResolverRegistry")
def nameResolverRegistry = nameResolverRegistryClass.getMethod("getDefaultRegistry").invoke(null)
def defaultScheme = nameResolverRegistryClass.getMethod("getDefaultScheme").invoke(nameResolverRegistry)
if (defaultScheme != "dns") {
throw new GradleException(
"grpc default NameResolver scheme is '${defaultScheme}' instead of 'dns' in ${jarFile.name} " +
"-- shadowJar's merge of META-INF/services/io.grpc.NameResolverProvider regressed."
)
}
def loadBalancerRegistryClass = loader.loadClass("io.grpc.LoadBalancerRegistry")
def loadBalancerRegistry = loadBalancerRegistryClass.getMethod("getDefaultRegistry").invoke(null)
if (loadBalancerRegistryClass.getMethod("getProvider", String).invoke(loadBalancerRegistry, "pick_first") == null) {
throw new GradleException(
"pick_first LoadBalancerProvider missing from ${jarFile.name} " +
"-- shadowJar's merge of META-INF/services/io.grpc.LoadBalancerProvider regressed."
)
}
} finally {
loader.close()
}
}
}
check.dependsOn verifyShadedGrpc
// mergeServiceFiles() merges META-INF/services from every dependency, including the ones whose classes shadowJar
// excludes. A Jackson module listed but not present in the JAR makes ServiceLoader fail, and langchain4j's Json then
// cannot initialise, which breaks every AIAgent tool call (#531).
tasks.register("verifyShadedJacksonModules") {
dependsOn shadowJar
doLast {
def jarFile = shadowJar.archiveFile.get().asFile
new java.util.zip.ZipFile(jarFile).withCloseable { zip ->
def services = zip.getEntry("META-INF/services/com.fasterxml.jackson.databind.Module")
if (services == null) {
throw new GradleException("META-INF/services/com.fasterxml.jackson.databind.Module is missing in ${jarFile.name} -- no Jackson module would be registered.")
}
def entries = zip.getInputStream(services).getText("UTF-8").readLines()*.trim().findAll { it && !it.startsWith("#") }
def missing = entries.findAll { zip.getEntry(it.replace('.', '/') + ".class") == null }
if (missing) {
throw new GradleException(
"META-INF/services/com.fasterxml.jackson.databind.Module in ${jarFile.name} lists classes the JAR does not contain: ${missing} " +
"-- ServiceLoader will throw 'Provider ... not found' and every AIAgent tool call breaks."
)
}
// A module whose class is packaged but no longer registered would break tool calls at
// runtime. The entry is contributed by the dependency that ships the class, so only
// require it while that dependency is still on the classpath.
def nullableModule = "org.openapitools.jackson.nullable.JsonNullableModule"
if (zip.getEntry(nullableModule.replace('.', '/') + ".class") != null && !entries.contains(nullableModule)) {
throw new GradleException(
"${nullableModule} is packaged in ${jarFile.name} but no longer registered in " +
"META-INF/services/com.fasterxml.jackson.databind.Module -- the file was emptied instead of pruned. " +
"The entry is contributed by the jackson-databind-nullable dependency."
)
}
}
}
}
check.dependsOn verifyShadedJacksonModules
/**********************************************************************************************************************\
* Version
**********************************************************************************************************************/
release {
preCommitText = 'chore(version):'
preTagCommitMessage = 'update to version'
tagCommitMessage = 'tag version'
newVersionCommitMessage = 'update snapshot version'
tagTemplate = 'v${version}'
buildTasks = ['classes']
git {
requireBranch.set('main')
}
}
/**********************************************************************************************************************\
* Dev
**********************************************************************************************************************/
idea {
module {
downloadJavadoc = true
downloadSources = true
}
}
// Build the UI module before packaging (only if ui/ directory exists)
if (file('ui').exists()) {
tasks.register('npmInstallUI', com.github.gradle.node.npm.task.NpmTask) {
args = ['install', '--fetch-retries=5', '--fetch-retry-mintimeout=5000', '--fetch-retry-maxtimeout=60000']
workingDir = file('ui')
}
tasks.register('buildUI', com.github.gradle.node.npm.task.NpmTask) {
dependsOn 'npmInstallUI'
args = ['run', 'build', '--', '--outDir', '../src/main/resources/plugin-ui']
workingDir = file('ui')
}
// Runs the Storybook `play` functions headlessly (jsdom) so CI catches UI regressions.
tasks.register('testUI', com.github.gradle.node.npm.task.NpmTask) {
dependsOn 'npmInstallUI'
args = ['run', 'test']
workingDir = file('ui')
}
processResources.dependsOn 'buildUI'
shadowJar.dependsOn 'buildUI'
tasks.named('check').configure { dependsOn 'testUI' }
}