简体   繁体   中英

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

You can use <properties> in the parent pom.xml and use them in the child pom.xml files.

In parent 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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