IntelliJ 2022.2.3构建时Maven资源编译复制失败求助
解决IntelliJ IDEA中Maven资源复制失败问题
问题场景
在IntelliJ IDEA v2022.2.3执行构建/重新构建操作时,触发以下错误:
Maven resources compiler: Failed to copy 'absolute_path_to_module/src/test/test-resources/test-app-camel-settings.properties' to 'absolute_path_to_module/target/test-classes/.': Couldn't copy [absolute_path_to_module/src/test/test-resources/test-app-camel-settings.properties] to [absolute_path_to_module/target/test-classes/.]
已尝试以下操作但无效:
- 构建及重新构建项目/模块
- 执行
mvn clean install命令 - 清除缓存并重启IDE
- 将项目回滚至上次正常运行的版本
针对性解决方法
1. 排查文件占用与权限
- 关闭所有可能占用
test-app-camel-settings.properties的进程(比如打开该文件的编辑器、同步工具),再重新构建。 - 检查源文件和
target/test-classes目录的读写权限,确保当前用户能修改、写入这些路径下的内容。
2. 校验Maven资源配置
打开项目模块的pom.xml,检查<build>节点下的<testResources>配置:
<testResources> <testResource> <directory>src/test/test-resources</directory> <includes> <include>**/*.properties</include> </includes> </testResource> </testResources>
确认directory路径和实际文件位置完全匹配,没有拼写错误或路径格式问题。
3. 手动清理目标目录
直接删除模块下的target文件夹,然后在终端执行mvn clean install,再回到IDE中重新构建。自动清理偶尔会有残留,手动删除能彻底清空旧文件。
4. 检查IDE的Maven配置
打开IDE设置(Windows/Linux:File > Settings;Mac:IntelliJ IDEA > Settings),进入Build, Execution, Deployment > Build Tools > Maven:
- 切换到本地安装的Maven版本,避免IDE内置版本的兼容问题。
- 确认
Maven home directory路径正确,User settings file和Local repository配置无异常。
5. 验证源文件完整性
检查test-app-camel-settings.properties是否损坏:比如文件为空、存在乱码或特殊字符。可以尝试重新创建该文件,复制原有内容后再执行构建。
内容的提问来源于stack exchange,提问作者user19717413
相关产品推荐
相关产品推荐

