This is an automated email from the ASF dual-hosted git repository.
jshao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new cd4c26e57d [#8732] fix(flink): Remove slf4j from Flink connector
runtime jar (#9310)
cd4c26e57d is described below
commit cd4c26e57d4006422cdf7f85f425010bcd9008d2
Author: FANNG <[email protected]>
AuthorDate: Mon Dec 1 15:19:06 2025 +0900
[#8732] fix(flink): Remove slf4j from Flink connector runtime jar (#9310)
### What changes were proposed in this pull request?
Remove slf4j from Flink connector runtime jar
### Why are the changes needed?
Fix: #8732
### Does this PR introduce _any_ user-facing change?
no
### How was this patch tested?
add tests
---
flink-connector/flink-runtime/build.gradle.kts | 21 ++++++++-
.../flink/runtime/TestRuntimeJarDependencies.java | 54 ++++++++++++++++++++++
2 files changed, 74 insertions(+), 1 deletion(-)
diff --git a/flink-connector/flink-runtime/build.gradle.kts
b/flink-connector/flink-runtime/build.gradle.kts
index 87a3a85fb2..5734527ff8 100644
--- a/flink-connector/flink-runtime/build.gradle.kts
+++ b/flink-connector/flink-runtime/build.gradle.kts
@@ -52,20 +52,39 @@ configurations.all {
dependencies {
implementation(project(":clients:client-java-runtime", configuration =
"shadow"))
implementation(project(":flink-connector:flink"))
+
+ testImplementation(libs.junit.jupiter.api)
+ testRuntimeOnly(libs.junit.jupiter.engine)
}
-tasks.withType<ShadowJar>(ShadowJar::class.java) {
+val shadowJarTask = tasks.named<ShadowJar>("shadowJar")
+
+shadowJarTask.configure {
isZip64 = true
configurations = listOf(project.configurations.runtimeClasspath.get())
archiveFileName.set("$baseName-$version.jar")
archiveClassifier.set("")
+ exclude("org/slf4j/**")
+ exclude("META-INF/maven/org.slf4j/**")
+
// Relocate dependencies to avoid conflicts
relocate("com.google", "org.apache.gravitino.shaded.com.google")
relocate("google", "org.apache.gravitino.shaded.google")
relocate("org.apache.hc", "org.apache.gravitino.shaded.org.apache.hc")
}
+tasks.test {
+ useJUnitPlatform()
+ dependsOn(shadowJarTask)
+ doFirst {
+ systemProperty(
+ "shadowJarPath",
+ shadowJarTask.get().archiveFile.get().asFile.absolutePath
+ )
+ }
+}
+
publishing {
publications {
withType<MavenPublication>().configureEach {
diff --git
a/flink-connector/flink-runtime/src/test/java/org/apache/gravitino/flink/runtime/TestRuntimeJarDependencies.java
b/flink-connector/flink-runtime/src/test/java/org/apache/gravitino/flink/runtime/TestRuntimeJarDependencies.java
new file mode 100644
index 0000000000..0f41c78a7f
--- /dev/null
+++
b/flink-connector/flink-runtime/src/test/java/org/apache/gravitino/flink/runtime/TestRuntimeJarDependencies.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.flink.runtime;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.stream.Collectors;
+import org.junit.jupiter.api.Test;
+
+class TestRuntimeJarDependencies {
+
+ @Test
+ void shadowJarShouldNotBundleSlf4j() throws IOException {
+ String jarPath = System.getProperty("shadowJarPath");
+ assertNotNull(jarPath, "shadowJarPath system property should be provided
by the build");
+
+ File runtimeJar = new File(jarPath);
+ assertTrue(runtimeJar.exists(), "shadow jar does not exist: " +
runtimeJar);
+
+ try (JarFile jarFile = new JarFile(runtimeJar)) {
+ List<String> entries =
jarFile.stream().map(JarEntry::getName).collect(Collectors.toList());
+ boolean hasSlf4jClasses = entries.stream().anyMatch(entry ->
entry.startsWith("org/slf4j/"));
+ boolean hasSlf4jMetadata =
+ entries.stream().anyMatch(entry ->
entry.startsWith("META-INF/maven/org.slf4j/"));
+ assertFalse(
+ hasSlf4jClasses,
+ "Flink connector runtime jar should rely on Flink provided slf4j
instead of shading it");
+ assertFalse(hasSlf4jMetadata, "SLF4J metadata should not be packaged in
runtime jar");
+ }
+ }
+}