mavenmaven-pluginmaven-compiler-plugin

Maven compiler plugin cannot resolve maven dependencies with version specified in included bill of material (bom)


We currently have this bill of material (bom) configured for all our projects (libraries and microservices)

           <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin.version}</version>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </path>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                        </path>
                        <path>
                            <groupId>org.hibernate</groupId>
                            <artifactId>hibernate-jpamodelgen</artifactId>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
 ...

And we have a parent pom in which we define common behavior for all our microservices in which we include this bom.

    <dependencyManagement>
        <dependencies>

            <dependency>
                <groupId>nl.bro</groupId>
                <artifactId>jakarta.bro-bill-off-material</artifactId>
                <version>${bro-bill-off-material.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            ... 

And somewhat further in the file we define the build.plugins.plugin

           <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin.version}</version>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </path>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                        </path>
                        <path>
                            <groupId>org.hibernate</groupId>
                            <artifactId>hibernate-jpamodelgen</artifactId>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>

Note the versions are missing because we defined the versions in the bom. I would expect that maven would pick this up when we let a microservice project derive from this parent.

However this does not seem to work. We get an error message:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project jakarta.common-shared: Resolution of annotationProcessorPath dependencies failed: version can neither be null,
 empty nor blank -> [Help 1]

This strikes me as odd. Why would I have to redefine the version of MapStruct, Lombok or Hibernate modelgen? Isn't it the essence of a bill of material to have centralized version control of your dependencies?


Solution

  • annotationProcessorPaths will resolve versions from dependencyManagement starting with version 3.12.0

    MCOMPILER-391