aliopi
aliopi

Reputation: 3842

Mapstruct mapper in src/test/java not generated by maven build

Just as the title says, I have a mapper interface in src/test/java, which is not generated by the mapstruct processor.

In the same project, all mappers in src/main/java are generated. Is this expected behaviour?

How do I generate the mappers inside the test sources?

Edit (more info):

Simplified Maven module structure:

root_project
-> module_1

pom.xml of root_project

<build>
    <pluginManagement>
           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>1.1.0.Final</version>
                        </path>
                    </annotationProcessorPaths>
                    <compilerArgs>
                        <compilerArg>
                            -Amapstruct.defaultComponentModel=spring
                        </compilerArg>
                    </compilerArgs>
                </configuration>
            </plugin>
            ...

The pom.xml of module_1 is basically empty:

<dependencies>

    <dependency>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct-jdk8</artifactId>
        <scope>compile</scope>
    </dependency>

Upvotes: 3

Views: 3267

Answers (1)

Marcio LSA
Marcio LSA

Reputation: 304

I had the same problem and fixed it changing the maven compiler plugin version. Please notice the versions: Compiler 3.5.1 and Mapstruct 1.1.0.Final

            <!-- compiler plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <dependencies>
                    <dependency>
                        <groupId>org.mapstruct</groupId>
                        <artifactId>mapstruct-jdk8</artifactId>
                        <version>1.1.0.Final</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <optimize>true</optimize>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>1.1.0.Final</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>

Upvotes: 7

Related Questions