1. Java
  2. Tutorial

Create Project

Create a new directory anywhere you’d like for this project:

mkdir kafka-java-getting-started && cd kafka-java-getting-started

Create the following Gradle build file for the project, named build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "gradle.plugin.com.github.jengelman.gradle.plugins:shadow:7.0.0"
    }
}

plugins {
    id "java"
    id "idea"
    id "eclipse"
}

sourceCompatibility = "1.11"
targetCompatibility = "1.11"
version = "0.0.1"

repositories {
    mavenCentral()
}

apply plugin: "com.github.johnrengelman.shadow"

dependencies {
    implementation group: 'org.slf4j', name: 'slf4j-nop', version: '2.0.3'
    implementation group: 'org.apache.kafka', name: 'kafka-clients', version: '3.6.0'
}

jar {
    manifest {
        attributes(
                "Class-Path": configurations.compileClasspath.collect { it.getName() }.join(" "),
                "Main-Class": "io.streamnative.developer.ProducerExample"
        )
    }
}

shadowJar {
    archiveBaseName = "kafka-java-getting-started"
    archiveClassifier = ''
}
Previous
Prerequisites