ZhangZhihui's Blog  

Here are the correct steps to compile flink-connector-kafka-4.0.1 from source into a JAR file.


How to Build flink-connector-kafka-4.0.1 From Source

Apache Flink modules (including connectors) use Maven for building.

1. Install Prerequisites

Make sure you have:

✔ Java

Flink 4.x typically requires Java 11 or 17.

java -version

✔ Maven

mvn -version

If you don’t have Maven, install it via your package manager or from:
https://maven.apache.org/download.cgi


2. Download the Source

If you already downloaded a tarball/zip of flink-connector-kafka-4.0.1, extract it:

tar -xvf flink-connector-kafka-4.0.1-src.tgz
cd flink-connector-kafka-4.0.1

 

 

3. Build the Connector

Run:

mvn clean package -DskipTests

If everything is fine, Maven will produce JARs under:

target/

📌 Final Jar Location

For this module specifically, your JAR will be generated at:

flink-connector-kafka-4.0.1/target/flink-connector-kafka-4.0.1.jar

(or a similar filename like flink-connector-kafka-4.0.1-shaded.jar depending on the module)

 

I ran 'mvn clean install -DskipTests' and it's been downloading a large number of .pom files, is it normal?
 
ChatGPT said:

Yes — this is completely normal when building a Maven project like the Flink Kafka connector.

Here’s why:


✅ Why Maven Downloads Many .pom Files

1. Maven resolves the entire dependency tree

Flink connectors rely on many dependencies:

  • Flink core libraries

  • Kafka client

  • Shaded libraries

  • Logging

  • Testing dependencies

  • Plugin definitions

  • Transitive dependencies

Each dependency has its own POM file that describes more dependencies → leading to many downloads.


✅ 2. If this is your first Maven build on this machine

Your local Maven repository (~/.m2/repository/) starts empty.

So Maven must download every dependency needed by the project (and plugins), which easily amounts to hundreds of .pom + .jar files.

This only happens once.
Future builds will be fast because Maven uses the cached local repository.


✅ 3. Multi-module projects download even more

The Flink connector repo usually contains modules like:

  • flink-connector-base

  • flink-connector-kafka

  • flink-connector-test-utils

  • flink-connector-shaded

  • etc.

Each module triggers its own dependency resolution.

So lots of downloads = normal.


📌 When you should be concerned

Only if you see:

  • very slow download speeds

  • repeated download failures

  • Maven stuck retrying the same dependency

  • errors like Could not resolve dependencies

 

 

'mvn clean install -DskipTests' ran successfully, the 'target' directory was created but there's no flink-connector-kafka-4.0.1.jar in it, instead there's a file named flink-connector-kafka-parent-4.0.1-shaded.pom.
 
ChatGPT said:

This is expected behavior — the directory you are looking at is not the actual Kafka connector module, but the parent module.

That’s why you’re only seeing:

flink-connector-kafka-parent-4.0.1-shaded.pom

and no JAR.


✅ Why no JAR was produced

The module flink-connector-kafka-parent is:

  • a parent POM module

  • contains no Java code

  • therefore produces no JAR

  • only produces a POM file

The actual Kafka connector JAR is produced in a submodule.


📌 Find the real connector module

Inside the source tree, you should see a folder like:

flink-connector-kafka/
flink-connector-kafka-runtime/
flink-connector-kafka-base/

Depending on Flink Kafka connector version (3.x vs 4.x), the actual JAR is usually in:

flink-connector-kafka/flink-connector-kafka-runtime/target/

or sometimes:

flink-connector-kafka/target/

Look for files like:

flink-connector-kafka-4.0.1.jar
flink-connector-kafka-runtime-4.0.1.jar
flink-connector-kafka-4.0.1-shaded.jar

 


👉 How to quickly find the JAR

Run this at the root of the project:

find . -name "*kafka*4.0.1*.jar"

This will show exactly where the jar was generated.


📌 If nothing is produced

It may mean:

The module is not built by default (common in connector repos)

Some Apache connector repos require building all modules:

mvn -pl flink-connector-kafka -am clean package -DskipTests

This explicitly builds the Kafka connector and all required modules.


 

You said:
I found the jar file under flink-connector-kafka-4.0.1/flink-connector-kafka/target . Thanks.

 

frank@ZZHPC:~/download/flink-connector-kafka-4.0.1/flink-connector-kafka/target$ cp flink-connector-kafka-4.0.1.jar $FLINK_HOME/lib

 

posted on 2025-12-02 21:53  ZhangZhihuiAAA  阅读(2)  评论(0)    收藏  举报