diff --git a/runners/google-cloud-dataflow-java/build.gradle b/runners/google-cloud-dataflow-java/build.gradle index 0f1af6aab269..34297ecba510 100644 --- a/runners/google-cloud-dataflow-java/build.gradle +++ b/runners/google-cloud-dataflow-java/build.gradle @@ -89,7 +89,8 @@ dependencies { implementation project(path: ":sdks:java:core", configuration: "shadow") implementation project(":sdks:java:extensions:avro") implementation project(":sdks:java:extensions:google-cloud-platform-core") - implementation project(":sdks:java:io:kafka") + // io-kafka is only used in PTransform override so it is optional + provided project(":sdks:java:io:kafka") implementation project(":sdks:java:io:google-cloud-platform") implementation project(":runners:core-construction-java") implementation library.java.avro diff --git a/runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowRunner.java b/runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowRunner.java index 5d2b7d190227..8ea366d4a997 100644 --- a/runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowRunner.java +++ b/runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowRunner.java @@ -565,7 +565,13 @@ private List getOverrides(boolean streaming) { new StreamingPubsubIOWriteOverrideFactory(this))); } - overridesBuilder.add(KafkaIO.Read.KAFKA_READ_OVERRIDE); + try { + overridesBuilder.add(KafkaIO.Read.KAFKA_READ_OVERRIDE); + } catch (NoClassDefFoundError e) { + // Do nothing. io-kafka is an optional dependency of runners-google-cloud-dataflow-java + // and only needed when KafkaIO is used in the pipeline. + } + overridesBuilder.add(SubscribeTransform.V1_READ_OVERRIDE); if (!hasExperiment(options, "enable_file_dynamic_sharding")) {