我使用google/auto-value在maven项目中创建不变的值类。
<?xml version="1.0" encoding="UTF-8"?>
<project 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"
xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
[...]
<packaging>war</packaging>
<properties>
<auto-value.version>1.7</auto-value.version>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>${auto-value.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value-annotations</artifactId>
<version>${auto-value.version}</version>
</dependency>
[...]
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>这就像使用命令行界面(例如mvn clean test)的护身符,但在IntelliJ项目构建过程中会产生错误:
Error:java: java.lang.NoClassDefFoundError: com/google/auto/service/AutoService
com.google.auto.service.AutoService值得注意的是:正确的源代码被生成到generated-sources/annotations/...中,但是IntelliJ构建在此步骤之后失败,并且不会创建生成的测试源代码目录generated-test-sources/...。
虽然这个问题可以通过向maven-compiler-plugin添加另一个批注处理器路径来轻松解决
<path>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>1.0-rc6</version>
</path>此修复程序的缺点是,每当auto-value-dependency版本发生更改时,都会查找并手动更改auto-service版本。有没有明显的错误,我在我的pom文件或在IntelliJ的设置,我不知道?据我所知,当我将项目导入到IntelliJ中时,创建了正确的批注处理配置文件。
发布于 2019-11-30 03:01:23
如果它是使用mvn构建的,而不是从IntelliJ内部构建的,那么它看起来就像是IntelliJ中的一个错误。我也看到了同样的事情。有一种配置AutoValue的替代方法可以避免这个问题:
<dependencies>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value-annotations</artifactId>
<version>1.7</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>1.7</version>
<optional>true</optional>
</dependency>
</dependencies>在这种情况下,您不需要<annotationProcessorPaths>的东西。在不利方面,显然存在一些风险,即AutoValue注释处理器( auto-value工件)或它的依赖项可能会进入已构建的项目。
https://stackoverflow.com/questions/58671279
复制相似问题