英文:
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 开始。
今天的版本是 3.12.0,但尚未发布。
我会在准备好时通知您。
英文:
annotationProcessorPaths
will resolve versions from dependencyManagement
starting with version 3.12.0
Today version 3.12.0 is not released yet.
I will let you know when will be ready.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论