Without seeing your Gradle file, it’ll be difficult to help much, but similar to Maven, your jar may not have the necessary classpath or dependencies included (i.e kafka-clients)
Please try using gradle shadow plugin to create a shaded fat jar, then run that with Java, not gradlew
I struggled with this same issue for a long time, trying to use WSL on my desktop, then Amazon Linux in EC2, enabling debug logs, modifying the gradle config to point to a specific Java version, updating JAVA_HOME, outputting the classpath for analysis, setting the thread’s context class loader to null, and adding code to reference and use StringSerializer.class to ensure that it could actually be picked up by the ClassLoader.
None of it made any difference. What finally resolved the issue was changing the following:
// THIS FAILS
producerConfigs.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "StringSerializer.class");
producerConfigs.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "KafkaProtobufSerializer.class");
// THIS WORKS
producerConfigs.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
producerConfigs.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "io.confluent.kafka.serializers.protobuf.KafkaProtobufSerializer");