Maven编译插件无法解析包含在物料清单(BOM)中指定版本的Maven依赖项。

huangapple go评论60阅读模式
英文:

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

问题

我们目前为所有项目(库和微服务)配置了这个物料清单(BOM)。

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

并且我们有一个父POM,在其中为所有微服务定义了共同的行为,我们在其中包含了这个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>

            ... 

在文件中稍后,我们定义了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>

请注意,版本信息已经缺失,因为我们在BOM中定义了版本。我原本希望当我们让微服务项目从这个父项目派生时,Maven会自动识别这一点。

然而,似乎这并没有起作用。我们收到了错误消息:

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

这让我感到奇怪。为什么我需要重新定义MapStruct、Lombok或Hibernate modelgen的版本?难道物料清单的本质不是要集中控制依赖项的版本吗?

英文:

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?

答案1

得分: 3

annotationProcessorPaths 将从 dependencyManagement 中解析版本,从版本 3.12.0 开始。

MCOMPILER-391

今天的版本是 3.12.0,但尚未发布。
我会在准备好时通知您。

英文:

annotationProcessorPaths will resolve versions from dependencyManagement starting with version 3.12.0

MCOMPILER-391

Today version 3.12.0 is not released yet.
I will let you know when will be ready.

huangapple
  • 本文由 发表于 2023年6月22日 19:46:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76531552.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定