Gradle is a popular choice for Kafka projects in Java
Before developing Kafka producers and consumers in Java, we’ll have to set up a simple Kafka Java project that includes common dependencies that we’ll need, namely:- Kafka dependencies
- Logging dependencies
Creating a Kafka Gradle project with build.gradle and setting up dependencies
In IntelliJ IDEA, create a new Java Gradle project (File > New > Project)
Then add your Gradle project attributes
The build tool Gradle contains a **build.gradle** file. The build.gradle is a default Gradle file that carries all the information regarding the Group and Version values . The user needs to define all the necessary project dependencies in the build.gradle file. Go to the build.gradle file.
Define the Kafka Dependencies in the dependencies { ... } block.
Add a dependency for Kafka client and logging dependencies as shown below
Now, we have set all the required dependencies. Let’s try the Simple Hello World example.
Creating your first class
Create a java package say,io.conduktor.demos.kafka.HelloWorld
While creating the java package, follow the package naming conventions. Finally, create the sample application program as shown below.
0. This means that your Java application has run successfully.
Expand the ‘External Libraries’ on the Project panel and verify that it displays the dependencies that we added for the project in build.gradle file
We have created a sample Java project that includes all the needed dependencies. This will form the basis for creating Java producers and consumers next.