Dagger2 Maven:com.google.devtools.ksp:symbol-processing-api:jar:1 缺少 POM

Posted

技术标签:

【中文标题】Dagger2 Maven:com.google.devtools.ksp:symbol-processing-api:jar:1 缺少 POM【英文标题】:Dagger2 Maven: Missing POM for com.google.devtools.ksp:symbol-processing-api:jar:1 【发布时间】:2021-10-25 13:21:01 【问题描述】:

我是 Dagger 的新手。这是我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <parent>
    <artifactId>trace-ingester</artifactId>
    <groupId>com.pandepra</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>

  <artifactId>trace-ingester-deploy</artifactId>

  <properties>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
  </properties>

  <dependencies>

    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-streaming-kafka-0-10_$scala.version.major</artifactId>
    </dependency>

    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-sql_$scala.version.major</artifactId>
    </dependency>

    <dependency>
      <groupId>com.typesafe</groupId>
      <artifactId>config</artifactId>
    </dependency>

    <dependency>
      <groupId>com.pandepra</groupId>
      <artifactId>trace-ingester-module</artifactId>
      <version>1.0-SNAPSHOT</version>
      <scope>compile</scope>
    </dependency>

    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-streaming_$scala.version.major</artifactId>
    </dependency>

    <dependency>
      <groupId>org.apache.kafka</groupId>
      <artifactId>kafka-clients</artifactId>

    </dependency>

    <dependency>
      <groupId>com.google.dagger</groupId>
      <artifactId>dagger</artifactId>
    </dependency>

  </dependencies>

  <build>
    <plugins>
      <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>
            </path>
          </annotationProcessorPaths>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.2.0</version>
        <executions>
          <execution>
            <id>create-fat-jar</id>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <artifactSet>
                <excludes>META-INF/*.SF</excludes>
                <excludes>META-INF/*.DSA</excludes>
                <excludes>META-INF/*.RSA</excludes>
                <includes>
                  <include>org.apache.spark:spark-streaming-kafka-0-10_$scala.version.major</include>
                  <include>org.apache.spark:spark-sql_$scala.version.major</include>
                  <include>org.apache.spark:spark-streaming_$scala.version.major</include>
                  <include>com.typesafe:config</include>
                </includes>
              </artifactSet>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <mainClass>com.pandepra.traceingester.TraceIngesterApplication</mainClass>
                </transformer>
              </transformers>
              <finalName>trace-ingester-uber-jar</finalName>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>

应用程序在 Intellij 中运行良好。但是,在执行maven clean install 时,我收到以下错误:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:compile (default-compile) on project trace-ingester-module: Resolution of annotationProcessorPath dependencies failed: Missing:
[ERROR] ----------
[ERROR] 1) com.google.devtools.ksp:symbol-processing-api:jar:1.5.20-1.0.0-beta03
[ERROR] 
[ERROR]   Try downloading the file manually from the project website.
[ERROR] 
[ERROR]   Then, install it using the command: 
[ERROR]       mvn install:install-file -DgroupId=com.google.devtools.ksp -DartifactId=symbol-processing-api -Dversion=1.5.20-1.0.0-beta03 -Dpackaging=jar -Dfile=/path/to/file
[ERROR] 
[ERROR]   Alternatively, if you host your own repository you can deploy the file there: 
[ERROR]       mvn deploy:deploy-file -DgroupId=com.google.devtools.ksp -DartifactId=symbol-processing-api -Dversion=1.5.20-1.0.0-beta03 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
[ERROR] 
[ERROR]   Path to dependency: 
[ERROR]         1) com.google.dagger:dagger-compiler:jar:2.38.1
[ERROR]         2) com.google.dagger:dagger-spi:jar:2.38.1
[ERROR]         3) com.google.devtools.ksp:symbol-processing-api:jar:1.5.20-1.0.0-beta03
[ERROR] 
[ERROR] ----------
[ERROR] 1 required artifact is missing.
[ERROR] 
[ERROR] for artifact: 
[ERROR]   com.google.dagger:dagger-compiler:jar:2.38.1
[ERROR] 
[ERROR] from the specified remote repositories:
[ERROR]   central (https://repo.maven.apache.org/maven2, releases=true, snapshots=false)
[ERROR] Path to dependency: 
[ERROR]         1) com.google.dagger:dagger-compiler:jar:2.38.1

官方文档不要求我们添加任何其他依赖项。我究竟做错了什么?这是一个多模块项目,有一个父级。

【问题讨论】:

【参考方案1】:

添加这个:

  <repositories>
    <repository>
      <id>google-maven</id>
      <name>Google Maven Repo</name>
      <url>https://maven.google.com</url>
    </repository>
  </repositories>

参考:https://github.com/google/dagger/releases#:~:text=New%20in%20Dagger-,New%20breaking%20changes,-Add%20the%20Google

【讨论】:

以上是关于Dagger2 Maven:com.google.devtools.ksp:symbol-processing-api:jar:1 缺少 POM的主要内容,如果未能解决你的问题,请参考以下文章

Android kotlin 使用Dagger2报错 InvocationTargetException 不能生成DaggerXXComponent

xml 在maven加入Dagger2和Lombok

Dagger2原理及使用

颤振 - 无法获取“https://google.bintray.com/exoplayer/com/google/android/gms/play-services-location/maven-m

maven报错 java.lang.RuntimeException: com.google.inject.CreationException: Unable to create injector,

maven报错 java.lang.RuntimeException: com.google.inject.CreationException: Unable to create injector,