Maven构建Spring Boot项目时无法找到Confluent Kafka Avro序列化器及Schema Registry Client依赖
Maven构建Spring Boot项目时无法找到Confluent Kafka Avro序列化器及Schema Registry Client依赖
你遇到的这个问题很常见,原因是Confluent官方的Kafka相关依赖(包括Avro序列化器、Schema Registry客户端)并不托管在Maven中央仓库,所以默认只配置了中央仓库的话,Maven肯定找不到这些包。
你遇到的具体错误信息如下:
Could not find artifact io.confluent:kafka-schema-registry-client:pom:7.8.0 in central
你当前的依赖配置是这样的:
<!-- https://mvnrepository.com/artifact/io.confluent/kafka-avro-serializer --> <dependency> <groupId>io.confluent</groupId> <artifactId>kafka-avro-serializer</artifactId> <version>7.8.0</version> </dependency> <!-- https://mvnrepository.com/artifact/io.confluent/kafka-schema-registry-client --> <dependency> <groupId>io.confluent</groupId> <artifactId>kafka-schema-registry-client</artifactId> <version>7.8.0</version> </dependency>
解决方案:添加Confluent专属Maven仓库
你只需要在pom.xml中添加Confluent官方的Maven仓库配置,就能让Maven找到这些依赖了,具体步骤如下:
- 在
pom.xml的<project>标签内,添加<repositories>节点配置Confluent仓库:
<repositories> <repository> <id>confluent</id> <url>https://packages.confluent.io/maven/</url> </repository> </repositories>
- (可选)如果你的项目需要用到Confluent的Maven插件,还可以补充添加
<pluginRepositories>节点:
<pluginRepositories> <pluginRepository> <id>confluent</id> <url>https://packages.confluent.io/maven/</url> </pluginRepository> </pluginRepositories>
- 配置完成后,重新执行Maven构建命令(
mvn clean install),就能成功拉取到所需的依赖了。
另外需要注意:Confluent的版本号需要和你项目中使用的Kafka版本兼容,7.8.0版本对应的Kafka版本是3.8.0,如果版本不匹配可能会出现兼容性问题,这点也需要留意哦。
备注:内容来源于stack exchange,提问作者Chandima Maduwantha
相关产品推荐
相关产品推荐

