sn4*_*n42 7 intellij-idea maven annotation-processing auto-value
我使用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>
Run Code Online (Sandbox Code Playgroud)
这就像使用 CLI(例如mvn clean test)的魅力一样,但在 IntelliJ 项目构建期间会产生错误:
Error:java: java.lang.NoClassDefFoundError: com/google/auto/service/AutoService
com.google.auto.service.AutoService
Run Code Online (Sandbox Code Playgroud)
值得注意的是:正确的源代码生成到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>
Run Code Online (Sandbox Code Playgroud)
此修复程序的缺点是auto-service在auto-value-dependency 版本更改时查找和手动更改版本。我在我的 pom 文件或 IntelliJ 中的设置中是否有明显的错误我不知道?据我所知,当我将项目导入 IntelliJ 时,会创建一个正确的注释处理配置文件。
我遇到了同样的问题,我在不接触代码的情况下修复了它。这是我所做的:
小智 4
mvn如果它是使用 IntelliJ 构建的,而不是从 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>
Run Code Online (Sandbox Code Playgroud)
在这种情况下你不需要这些<annotationProcessorPaths>东西。不利的一面是,AutoValue 注释处理器(auto-value工件)或其依赖项显然存在进入您构建的项目的风险。
| 归档时间: |
|
| 查看次数: |
1871 次 |
| 最近记录: |