Error ./gradlew runStreams -Pargs=basic

Hello, I’m running the code created in the Hands On: Basic Operations exercise, and it’s reporting this error below

training@training:~$ cd learn-kafka-courses/kafka-streams
training@training:~/learn-kafka-courses/kafka-streams$ ./gradlew runStreams -Pargs=basic
Starting a Gradle Daemon (subsequent builds will be faster)

Configure project :
Using example io.confluent.developer.basic.BasicStreams

Task :compileJava FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:compileJava’.

Duplicate key io.confluent.developer.basic.solution.BasicStreams (attempted merging values io/confluent/developer/basic/solution/BasicStreams.java and io/confluent/developer/basic/BasicStreams.java)

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

follow code used

package io.confluent.developer.basic;

import org.apache.kafka.common.serialization.Serdes;
import org.apache.kafka.streams.KafkaStreams;
import org.apache.kafka.streams.StreamsBuilder;
import org.apache.kafka.streams.StreamsConfig;
import org.apache.kafka.streams.kstream.Consumed;
import org.apache.kafka.streams.kstream.KStream;
import org.apache.kafka.streams.kstream.Produced;

import java.io.FileInputStream;
import java.io.IOException;
import java.time.Duration;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;

public class BasicStreams {

public static void main(String[] args) throws IOException {
    Properties streamsProps = new Properties();
    try (FileInputStream fis = new FileInputStream("src/main/resources/streams.properties")) {
        streamsProps.load(fis);
    }
    streamsProps.put(StreamsConfig.APPLICATION_ID_CONFIG, "basic-streams");

    StreamsBuilder builder = new StreamsBuilder();
    final String inputTopic = streamsProps.getProperty("basic.input.topic");
    final String outputTopic = streamsProps.getProperty("basic.output.topic");

    final String orderNumberStart = "orderNumber-";
    KStream<String, String> firstStream = builder.stream(inputTopic, Consumed.with(Serdes.String(), Serdes.String()));

    firstStream.peek((key, value) -> System.out.println("Incoming record - key " + key + " value " + value))
            .filter((key, value) -> value.contains(orderNumberStart))
            .mapValues(value -> value.substring(value.indexOf("-") + 1))
            .filter((key, value) -> Long.parseLong(value) > 1000)
            .peek((key, value) -> System.out.println("Outgoing record - key " + key + " value " + value))
            .to(outputTopic, Produced.with(Serdes.String(), Serdes.String()));

    try (KafkaStreams kafkaStreams = new KafkaStreams(builder.build(), streamsProps)) {
        final CountDownLatch shutdownLatch = new CountDownLatch(1);

        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            kafkaStreams.close(Duration.ofSeconds(2));
            shutdownLatch.countDown();
        }));
        TopicLoader.runProducer();
        try {
            kafkaStreams.start();
            shutdownLatch.await();
        } catch (Throwable e) {
            System.exit(1);
        }
    }
    System.exit(0);
}

}

Thanks for reporting this - I’m looking into it.

Hi @adriano.castelhoni - I can’t duplicate the error; the ./gradlew runStreams - Pargs=basic command runs as expected.
There have been some improvements to the project recently, can you confirm you’re using the latest revision from the GitHub repo?

Thanks,
Bill

Hi Bill, I used the Git clone that is in the exercise.

  1. Clone the course’s GitHub repository and load it into your favorite IDE or editor.

    git clone GitHub - confluentinc/learn-kafka-courses: Learn the basics of Apache Kafka® from leaders in the Kafka community with these video courses covering the Kafka ecosystem and hands-on exercises.

git clone https://github.com/confluentinc/learn-kafka-courses.git

OK - let me try from a fresh clone - I don’t expect it to be different, but I’ll give it a shot.

Hi @adriano.castelhoni ,

I tried a fresh repo clone, and everything worked as expected, so I’m scratching my head to figure out what could have gone wrong.
It shouldn’t matter since the project has a gradlew file, but what version of Gradle are you using? When you wrote the working solution, you edited the file in place, meaning you didn’t add an additional file?

-Bill

Hi Bill,

Information follows

training@training:~$ cd learn-kafka-courses/kafka-streams
training@training:~/learn-kafka-courses/kafka-streams$ gradle -version

Welcome to Gradle 5.4.1!

Here are the highlights of this release:

  • Run builds with JDK12
  • New API for Incremental Tasks
  • Updates to native projects, including Swift 5 support

For more details see https://docs.gradle.org/5.4.1/release-notes.html

(Attachment trace_basic_stream.txt is missing)

That’s a fairly old release. Can you try upgrading to 7.0.0 or greater (7.5.1 would be ideal) and see if that fixes your issue?