简体   繁体   English

maven 模块中的可配置注释处理器

[英]Configurable annotation processors in maven modules

We have multiple services that are using certain annotation processors.我们有多个使用某些注释处理器的服务。 All these services have 2 things in common - the same parent pom & a specific pom - import - dependency in dependencyManagement .所有这些服务有两个共同点——同一个父 pom 和一个特定的pom - import - dependency中的dependencyManagement项。 In the individual services we define processors using the snippet below在各个服务中,我们使用下面的代码片段定义处理器

  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <annotationProcessorPaths>
        <path>
          <artifactId>mapstruct-processor</artifactId>
          <groupId>org.mapstruct</groupId>
          <version>${mapstruct.version}</version>
        </path>
        <path>
          <artifactId>lombok</artifactId>
          <groupId>org.projectlombok</groupId>
          <version>${projectlombok.version}</version>
        </path>
      </annotationProcessorPaths>
    </configuration>
    <groupId>org.apache.maven.plugins</groupId>
  </plugin>

The issue here is that each service needs to define the version of the processor themselves.这里的问题是每个服务都需要自己定义处理器的版本。 I just do not want to add the processors to parent pom as there are number of services which do not use lombok or mapstruct, so do not want to add an extra processor for them.我只是不想将处理器添加到父 pom,因为有许多服务不使用 lombok 或 mapstruct,所以不想为它们添加额外的处理器。 Any solutions available where I could specify the version of processor preferably in bom dependency or else in parent pom and the services can just decide which of the processors they want to use?任何可用的解决方案,我可以最好在 bom 依赖项或父 pom 中指定处理器的版本,并且服务可以决定他们想要使用哪个处理器?

You can use <properties> in the parent pom.xml and use them in the child pom.xml files.您可以在父 pom.xml 中使用<properties>并在子 pom.xml 文件中使用它们。

In parent pom.xml在父 pom.xml

<properties>
  <project.lombok.version>1.2.3</project.lombok.version>
</properties>

In the child pom.xml where you need the version to be used在子 pom.xml 中您需要使用的版本

<artifactId>lombok</artifactId>
<groupId>org.projectlombok</groupId>
<version>${project.lombok.version}</version>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM