升级IntelliJ IDEA 2023.1.3后遭遇Mapstruct FilerException求助
以下是针对javax.annotation.processing.FilerException: Attempt to recreate a file for type com.example.mapper.PersonMapperImpl错误的可行解决办法:
检查注解处理器配置
打开File > Settings > Build, Execution, Deployment > Compiler > Annotation Processors,确保Enable annotation processing已勾选;取消勾选Obtain processors from project classpath,手动指定MapStruct处理器路径(或保持勾选但配合后续缓存清理操作);确认Store generated sources relative to选择Module content root,且target/generated-sources/annotations目录已被标记为Generated Sources Root。清理缓存与重新构建
执行Maven命令:mvn clean install -U,强制更新依赖并清理旧生成文件;同时清理IDEA缓存:File > Invalidate Caches... > 勾选Clear file system cache and local history > 点击Invalidate and Restart。对齐MapStruct版本与IDEA兼容性
升级MapStruct至最新稳定版(如1.5.5.Final),旧版本可能与IDEA 2023.1.x存在适配问题;确保pom.xml中依赖配置正确,处理器需放在annotationProcessorPaths中,示例配置:<properties> <mapstruct.version>1.5.5.Final</mapstruct.version> </properties> <dependencies> <dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct</artifactId> <version>${mapstruct.version}</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.11.0</version> <configuration> <source>17</source> <!-- 替换为你的项目JDK版本 --> <target>17</target> <annotationProcessorPaths> <path> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>${mapstruct.version}</version> </path> </annotationProcessorPaths> </configuration> </plugin> </plugins> </build>关闭并行编译
打开File > Settings > Build, Execution, Deployment > Compiler,取消勾选Build project automatically和Compile independent modules in parallel,避免并行编译引发的文件生成冲突。排查重复依赖
执行mvn dependency:tree,检查是否存在多版本MapStruct处理器依赖,通过<exclusions>排除多余的依赖项。
内容的提问来源于stack exchange,提问作者rcasia

