如何强制IntelliJ IDEA使用pom.xml配置运行测试?
解决方案
1. 强制指定Kotlin编译参数
打开File → Settings → Build, Execution, Deployment → Compiler → Kotlin Compiler:
- 将Target JVM version设置为项目对应的JDK版本(比如
1.8,匹配你的kotlin-stdlib-jdk8依赖) - 在Additional command line parameters中添加:
-api-version 1.3 -language-version 1.3 - 若为多模块项目,需确保每个模块的该配置一致,或在
Project Structure中统一设置模块的Kotlin版本。
2. 让IntelliJ完全遵循Maven配置
打开File → Settings → Build, Execution, Deployment → Build Tools → Maven → Importing:
- 勾选
Import Maven projects automatically(保证Maven配置自动同步) - 取消勾选
Override compiler parameters per-module(禁止IntelliJ自行覆盖编译参数) - 点击
Apply后,右键项目选择Maven → Reload Project重新导入配置。
3. 检查模块级Kotlin配置
打开File → Project Structure → Modules,选中报错的模块(如integration-test):
- 切换到
Kotlin标签页 - 将Language version和API version都设置为
1.3 - 确认Kotlin standard library选择的是Maven依赖中的版本(而非IntelliJ默认版本)
4. 清理缓存并重启IntelliJ
打开File → Invalidate Caches...,勾选Clear file system cache and local history,点击Invalidate and Restart。重启后重新运行测试即可。
内容的提问来源于stack exchange,提问作者SWiggels
相关产品推荐
相关产品推荐

