背景
個人maven
的settings.xml
配置的jdk
版本是1.8
,而公司配置的jdk
版本是1.7
,我修改本地配置如下
- 複製
settings.xml
爲settings-copy.xml
,修改jdk
版本爲jdk7
- 在
idea
設置Settings
和Project Structure
的jdk
版本爲jdk7
- 在
idea
設置maven
的settings
的路徑爲settings-copy.xml
- 執行
clean install
命令時報錯
<profile>
<id>development</id>
<activation>
<jdk>1.8</jdk>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
出現的問題
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project xxx: Compilation failure
[ERROR] Failure executing javac, but could not parse the error:
[ERROR] javac: 無效的目標發行版: 1.8
原因
idea
中配置的maven
路徑是settings-copy.xml
,但是mvn
執行命令時,默認找的是settings.xml
文件,因此會出現上述問題。
解決方法
- 修改
settings-copy.xm
l文件名爲settings.xml
,並將源文件重命名 idea
重新配置maven
路徑爲settings.xml
- 第一和第二步弄好之後,再次執行
clean install
即可