Maven:我可以在 annotationProcessorPath 中使用来自依赖管理的版本吗?

Maven: Can I use a version from dependency management in annotationProcessorPath?

我正在我的 dependencyManagement 中导入共享的“物料清单”(bom),如下所示:

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.mycompany</groupId>
      <artifactId>common-bom</artifactId>
      <version>1.2.3</version>
      <scope>import</scope>
      <type>pom</type>
    </dependency>
  </dependencies>
</dependencyManagement>

那个common-bom定义了版本,然后我就用它定义的任何版本,像这样:

<dependency>
  <groupId>org.projectlombok</groupId>
  <artifactId>lombok</artifactId>
</dependency>

这一切都很好,除了我也有这个

  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <annotationProcessorPaths combine.children="append">
        <annotationProcessorPath>
          <groupId>org.projectlombok</groupId>
          <artifactId>lombok</artifactId>
          <version>1.18.20</version>
        </annotationProcessorPath>
      </annotationProcessorPaths>
    </configuration>
  </plugin>

所以现在我无论如何都需要指定一个 lombok 版本,不是为了实际的依赖,而是为了注释处理器路径。有没有办法我可以以某种方式使用相同的值?例如,它可以作为 属性 存储在 common-bom 中吗?

这是不可能的,因为 maven-compiler-plugin 目前不遵守 dependencyManagement 规则(MCOMPILER-391,去投票吧!)。

你现在唯一能做的似乎是在父 pom 中声明一个 lombok.version 属性,并在你的 annotationProcessorPath 声明中使用它。

(注意 Spring Boot 已经为 Lombok 定义了这样一个 属性)