javamaven

mvn compiler plugin DependencyCoordinate error


According to the mapstruct docs, one should add the maven-compiler-plugin to the poml.xml s.t. the Mappers are generated. After fiddling with the correct source, target version for my JDK, I ran into this error, when building the project:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile
(default-compile) on project: Unable to parse configuration of mojo
org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile
for parameter source: Cannot find default setter in class
org.apache.maven.plugin.compiler.DependencyCoordinate -> [Help 1]

A snippet from my poml.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.5</version>
    </parent>

    <groupId>com.example</groupId>
    <artifactId>myproject</artifactId>
    <version>0.0.1</version>
    <name>myproject</name>
    <description>Example project</description>

    <properties>
        <org.mapstruct.version>1.5.5.Final</org.mapstruct.version>
        <java.version>17</java.version>
    </properties>

    <dependencies>
        <dependency>

            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct</artifactId>
            <version>${org.mapstruct.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

    </dependencies>
    <build>
        <pluginManagement>
            <plugins>
                 <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.1</version>
                    <configuration>
                        <annotationProcessorPaths>
                            <source>${java.version}</source>
                            <target>${java.version}</target>
                            <path>
                                <groupId>org.mapstruct</groupId>
                                <artifactId>mapstruct-processor</artifactId>
                                <version>${org.mapstruct.version}</version>
                            </path>
                        </annotationProcessorPaths>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

Solution

  • One can add only the package mapstruct-processor instead of editing the maven-compiler-plugin configuration, which (according to my understanding) is already provided & set by maven itself.

    <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct-processor</artifactId>
            <version>1.5.5.Final</version>
    </dependency>