Control Annotation Processor Configurations in Maven Project

已回答

Hi all,

When using both Lombok and MapStruct, each time I refresh my Maven project, the annotation processor configuration gets reset to:

  1. Store generated sources relative to Module Content Root (from Module Output Directory)
  2. a direct processor path

cf. 

from what I continually need to reset it to, which is

 

  1.  Store generated sources relative to Module Output Directory
  2. Obtain processors from project classpath

This results in the exception described in https://stackoverflow.com/questions/73223385/problem-with-internal-error-in-the-mapping-procesor-while-using-mapstruct occurring whenever I rebuild the project or try to run tests from the IDE, requiring me to delete `src/main/java/target as well as `target/generated-*`, which is a substantial development pain-point.

 

My maven compiler plugin configuration is:
 

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>${maven-compiler-plugin.version}</version> <!-- 3.13.0 -->
  <configuration>
    <source>${build.java.version}</source> <!-- 17 -->
    <target>${build.java.version}</target>
    <generatedSourcesDirectory>${project.build.directory}/generated-sources</generatedSourcesDirectory>
    <generatedTestSourcesDirectory>${project.build.directory}/generated-test-sources</generatedTestSourcesDirectory>
    <annotationProcessorPaths>
      <path>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct-processor</artifactId>
        <version>${org.mapstruct.version}</version> <!-- latest version>
      </path>
      <path>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>${lombok.version}</version> <!-- latest version -->
      </path>
      <path>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok-mapstruct-binding</artifactId>
        <version>${lombok-mapstruct-binding.version}</version> <!-- latest version -->
      </path>
    </annotationProcessorPaths>
    <compilerArgs>
      <arg>-Amapstruct.defaultComponentModel=jsr330</arg>
    </compilerArgs>
  </configuration>
</plugin>

The versions are inline, but this is pretty reliable behavior across a variety of versions, including:

 

  • maven-compiler-plugin: 3.13.0
  • mapstruct: 1.5.5.Final
  • Lombok: 1.18.30

My expectation would be that the Maven support would:

  • Generate sources relative to the module output directory
  • Obtain the annotation processors from the project classpath

by default.

Thanks in advance!

5

Hello, Josiah!

Thank you for reporting this!

I've reproduced the issue and it appears to be the same as the one described in IDEA-95926.

While the YouTrack Issue is quite old, I've reached out to the developers and confirmed that they are looking into it.

Please upvote the Issue to raise its' priority and keep an eye on it for further updates!

0

Any update on this? I have the same issue as Josiah Haswell 

We also use Lombok and MapStruct in a maven project and I need to change the settings back to “Obtain processors from project classpath” in the annotation processor when I reload my maven projects.

0

Ben Oeyen We are looking into this, but, I'm afraid, we don't have any ETAs yet.

Note that there was a known issue with the Annotation Processors, please make sure you're using the latest version of IDEA (2024.3.5).

0

请先登录再写评论。