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

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

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

问题

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

  1. <plugin>
  2. <artifactId>maven-compiler-plugin</artifactId>
  3. <version>${maven-compiler-plugin.version}</version>
  4. <configuration>
  5. <source>${maven.compiler.source}</source>
  6. <target>${maven.compiler.target}</target>
  7. <annotationProcessorPaths>
  8. <path>
  9. <groupId>org.projectlombok</groupId>
  10. <artifactId>lombok</artifactId>
  11. </path>
  12. <path>
  13. <groupId>org.mapstruct</groupId>
  14. <artifactId>mapstruct-processor</artifactId>
  15. </path>
  16. <path>
  17. <groupId>org.hibernate</groupId>
  18. <artifactId>hibernate-jpamodelgen</artifactId>
  19. </path>
  20. </annotationProcessorPaths>
  21. </configuration>
  22. </plugin>
  23. ...

并且我们有一个父POM,在其中为所有微服务定义了共同的行为,我们在其中包含了这个BOM。

  1. <dependencyManagement>
  2. <dependencies>
  3. <dependency>
  4. <groupId>nl.bro</groupId>
  5. <artifactId>jakarta.bro-bill-off-material</artifactId>
  6. <version>${bro-bill-off-material.version}</version>
  7. <type>pom</type>
  8. <scope>import</scope>
  9. </dependency>
  10. ...

在文件中稍后,我们定义了build.plugins.plugin

  1. <plugin>
  2. <artifactId>maven-compiler-plugin</artifactId>
  3. <version>${maven-compiler-plugin.version}</version>
  4. <configuration>
  5. <source>${maven.compiler.source}</source>
  6. <target>${maven.compiler.target}</target>
  7. <annotationProcessorPaths>
  8. <path>
  9. <groupId>org.projectlombok</groupId>
  10. <artifactId>lombok</artifactId>
  11. </path>
  12. <path>
  13. <groupId>org.mapstruct</groupId>
  14. <artifactId>mapstruct-processor</artifactId>
  15. </path>
  16. <path>
  17. <groupId>org.hibernate</groupId>
  18. <artifactId>hibernate-jpamodelgen</artifactId>
  19. </path>
  20. </annotationProcessorPaths>
  21. </configuration>
  22. </plugin>

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

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

  1. [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)

  1. <plugin>
  2. <artifactId>maven-compiler-plugin</artifactId>
  3. <version>${maven-compiler-plugin.version}</version>
  4. <configuration>
  5. <source>${maven.compiler.source}</source>
  6. <target>${maven.compiler.target}</target>
  7. <annotationProcessorPaths>
  8. <path>
  9. <groupId>org.projectlombok</groupId>
  10. <artifactId>lombok</artifactId>
  11. </path>
  12. <path>
  13. <groupId>org.mapstruct</groupId>
  14. <artifactId>mapstruct-processor</artifactId>
  15. </path>
  16. <path>
  17. <groupId>org.hibernate</groupId>
  18. <artifactId>hibernate-jpamodelgen</artifactId>
  19. </path>
  20. </annotationProcessorPaths>
  21. </configuration>
  22. </plugin>
  23. ...

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

  1. <dependencyManagement>
  2. <dependencies>
  3. <dependency>
  4. <groupId>nl.bro</groupId>
  5. <artifactId>jakarta.bro-bill-off-material</artifactId>
  6. <version>${bro-bill-off-material.version}</version>
  7. <type>pom</type>
  8. <scope>import</scope>
  9. </dependency>
  10. ...

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

  1. <plugin>
  2. <artifactId>maven-compiler-plugin</artifactId>
  3. <version>${maven-compiler-plugin.version}</version>
  4. <configuration>
  5. <source>${maven.compiler.source}</source>
  6. <target>${maven.compiler.target}</target>
  7. <annotationProcessorPaths>
  8. <path>
  9. <groupId>org.projectlombok</groupId>
  10. <artifactId>lombok</artifactId>
  11. </path>
  12. <path>
  13. <groupId>org.mapstruct</groupId>
  14. <artifactId>mapstruct-processor</artifactId>
  15. </path>
  16. <path>
  17. <groupId>org.hibernate</groupId>
  18. <artifactId>hibernate-jpamodelgen</artifactId>
  19. </path>
  20. </annotationProcessorPaths>
  21. </configuration>
  22. </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:

  1. [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,
  2. 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:

确定