![](/img/trans.png)
[英]How to use google protobuf compiler with maven-compiler-plugin
[英]How to use multiple annotation processors with maven-compiler-plugin
我有一個 spring 引導項目,它有 lombok 和 mapstruct,並使用 maven 作為構建工具。 我需要在編譯時處理注釋,生成的源代碼與最終的 jar 打包在一起。構建成功。 然而,最終的jar缺少mapstruct實現class。當我嘗試啟動spring引導應用程序時的錯誤是:
應用程序啟動失敗
描述:
com.some_org.service.salesforce.object.processor.SalesforceObjectProcessor 中的字段 salesforceObjectMapper 需要類型為“com.some_org.service.salesforce.object.mapper.SalesforceObjectMapper”的 bean,但無法找到。
行動:
考慮在您的配置中定義類型為“com.some_org.service.salesforce.object.mapper.SalesforceObjectMapper”的 bean。
這是我的 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>
最終通過在編譯階段使用執行覆蓋默認編譯目標來解決這個問題,如下所示:
<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>
我不知道這是否對某人有幫助,但如果你的 lombok 和 mapstruct 不能很好地相互配合,你可以使用lombok-mapstruct-binding
來解決沖突(你不需要把它放在execution
標簽)! 對我來說效果很好
<build>
<plugins>
<plugin>
..
<configuration>
..
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.4.2.Final</version>
</path>
</annotationProcessorPaths>
</plugin>
<plugins>
<build>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.