You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Dagger2多模块Maven项目执行clean install缺失ksp依赖报错

Dagger Maven编译缺失ksp依赖问题解决方案

问题根因

  • 报错实际发生在trace-ingester-module子模块,你提供的是trace-ingester-deploy子模块的配置,说明trace-ingester-module也依赖了Dagger,但未正确配置注解处理器,或配置和deploy模块不一致
  • Dagger 2.38+版本的dagger-spi组件依赖了com.google.devtools.ksp:symbol-processing-api,该组件仅发布在Google官方Maven仓库,你当前仅配置了Maven Central作为远程仓库,因此Maven命令行执行时无法拉取到该依赖
  • IntelliJ运行正常是因为IDE内置了Google仓库的拉取规则,或者本地缓存中已存在该依赖,不会触发缺失报错

解决方案

方案1:添加Google Maven仓库

在父POM的<repositories>节点中新增Google仓库配置,所有子模块会自动继承:

<repositories>
  <repository>
    <id>google-maven</id>
    <url>https://maven.google.com</url>
    <releases>
      <enabled>true</enabled>
    </releases>
    <snapshots>
      <enabled>false</enabled>
    </snapshots>
  </repository>
</repositories>

同时检查所有引用Dagger的子模块,都按照deploy模块的配置,正确添加dagger-compiler到注解处理器路径。

方案2:排除KSP依赖(纯Java项目推荐)

如果你的项目是纯Java开发,不需要用到Kotlin KSP注解处理能力,可以直接在注解处理器配置中排除KSP依赖,无需新增仓库:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.6.1</version>
  <configuration>
    <annotationProcessorPaths>
      <path>
        <groupId>com.google.dagger</groupId>
        <artifactId>dagger-compiler</artifactId>
        <version>2.38.1</version>
        <!-- 排除不需要的KSP依赖 -->
        <exclusions>
          <exclusion>
            <groupId>com.google.devtools.ksp</groupId>
            <artifactId>symbol-processing-api</artifactId>
          </exclusion>
        </exclusions>
      </path>
    </annotationProcessorPaths>
  </configuration>
</plugin>

注意:所有引入Dagger依赖的子模块都需要做相同的配置,包括报错的trace-ingester-module模块。

内容的提问来源于stack exchange,提问作者Prashant Pandey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.07 06:15:04