rvh*_*deg 0 java maven-compiler-plugin spring-boot mapstruct
I have a spring boot application with mapstruct where I get this warning on the maven-compiler-plugin testCompile phase:
[WARNING] The following options were not recognized by any processor: '[mapstruct.suppressGeneratorTimestamp]'
As I don't want warnings in my code I have been searching to solve this issue but the only thing that worked this far is to use <showWarnings>false</showWarnings>
我应该怎么做才能解决此警告而不将其静音?
申请文件:
pom.xml:
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0</version>
</parent>
<groupId>com.example</groupId>
<artifactId>test</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.5.3.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.5.3.Final</version>
</path>
</annotationProcessorPaths>
<showWarnings>true</showWarnings>
<compilerArgs>
<arg>
-Amapstruct.suppressGeneratorTimestamp=true
</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
Event.java :具有 1 个字段的 pojo:id
EventDTO.java:具有 1 个字段的 pojo:id
我的映射器:
import org.mapstruct.Mapper;
@Mapper(componentModel = "spring")
public interface EventMapper {
EventDTO eventToEventDto(Event event);
}
Run Code Online (Sandbox Code Playgroud)
映射器上的单元测试:
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class EventMapperTest {
@Test
void eventToEventDto() {
Event event = createEvent();
EventMapper mapper = new EventMapperImpl();
EventDTO eventDTO = mapper.eventToEventDto(event);
assertEquals(event.getId(), eventDTO.getId());
}
private Event createEvent() {
Event event = new Event();
event.setId(15);
return event;
}
}
Run Code Online (Sandbox Code Playgroud)
此警告很可能是因为测试代码中没有要映射的文件而引起的。将注释处理信息限制为编译任务而不是为test-compile和compile任务都设置它应该可以解决此问题。
如果我查对了,编译任务应该是使用 id 执行default-compile。因此,以下配置应该可以正常工作,而不会在任务中发出警告test-compile:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.5.3.Final</version>
</path>
</annotationProcessorPaths>
<showWarnings>true</showWarnings>
<compilerArgs>
<arg>
-Amapstruct.suppressGeneratorTimestamp=true
</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3906 次 |
| 最近记录: |