javaspring-bootmapstructmaven-compiler-plugin

"Warning: The following options were not recognized by any processor" for 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>

What should I do to resolve this warning without muting them?

Application files:

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>

Event.java : pojo with 1 field: id

EventDTO.java: pojo with 1 field: id

My mapper:

import org.mapstruct.Mapper;

@Mapper(componentModel = "spring")
public interface EventMapper {
    EventDTO eventToEventDto(Event event);
}

Unit test on the mapper:

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;
    }
}

Solution

  • This warning is most likely caused because there are no files to map in the test code. Limiting the annotation processing information to the compile task instead of setting it both for the test-compile and compile tasks should fix this.

    If I looked it up correctly the compile task should be the execution with the id default-compile. So the following configuration should work without giving the warning at the test-compile task:

    <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>