背景
个人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
即可 -
如果使用
cmd
命令行执行时,可以指定settings.xml
执行mvn
命令mvn clean install --settings E:\settings.xml