【问题标题】:How to use multiple annotation processors with maven-compiler-plugin如何通过 maven-compiler-plugin 使用多个注释处理器
【发布时间】:2020-07-23 08:41:53
【问题描述】:

我有一个带有 lombok 和 mapstruct 并使用 maven 作为构建工具的 spring boot 项目。我需要在编译时处理注释,生成的源与最终的 jar 一起打包。构建成功。但是,最终的 jar 缺少 mapstruct 实现类。我尝试启动spring boot应用程序时的错误是:


应用程序启动失败


说明:

字段 salesforceObjectMapper 在 com.some_org.service.salesforce.object.processor.SalesforceObjectProcessor 需要一个 bean 类型 'com.some_org.service.salesforce.object.mapper.SalesforceObjectMapper' 找不到。

行动:

考虑定义一个 bean 类型 'com.some_org.service.salesforce.object.mapper.SalesforceObjectMapper' 在您的配置中。

这是我的 maven-compiler-plugin 设置:

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.7.0</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <annotationProcessorPaths>
            <path>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.18.12</version>
            </path>
            <path>
                <groupId>org.mapstruct</groupId>
                <artifactId>mapstruct-processor</artifactId>
                <version>1.2.0.Final</version>
            </path>
        </annotationProcessorPaths>
        <compilerArgs>
            <compilerArg>-Amapstruct.suppressGeneratorTimestamp=true</compilerArg>
            <compilerArg>-Amapstruct.suppressGeneratorVersionInfoComment=true</compilerArg>
        </compilerArgs>
    </configuration>
</plugin>

【问题讨论】:

    标签: java spring-boot maven lombok mapstruct


    【解决方案1】:

    最终通过在编译阶段使用执行覆盖默认编译目标来解决此问题,如下所示:

    <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.7.0</version>
        <executions>
            <execution>
                <id>Compile With Annotation Processing</id>
                <phase>compile</phase>
                <goals>
                    <goal>compile</goal>
                </goals>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>1.18.12</version>
                        </path>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>1.2.0.Final</version>
                        </path>
                    </annotationProcessorPaths>
                    <compilerArgs>
                        <compilerArg>-Amapstruct.suppressGeneratorTimestamp=true</compilerArg>
                        <compilerArg>-Amapstruct.suppressGeneratorVersionInfoComment=true</compilerArg>
                    </compilerArgs>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-01
      • 2011-07-15
      • 2015-11-18
      • 1970-01-01
      • 2013-01-14
      • 1970-01-01
      • 2017-07-04
      • 2011-10-11
      相关资源
      最近更新 更多