我是一个新的“专家”...:-)
我在 Eclipse Mars 工作。
我创建了一个默认的maven项目,它默认使用JDK 1.5。 我想改用 1.8.31。
我当前的 POM 显示如下:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
On apache maven website我读到我需要将其更改\替换为这样的内容:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable><!-- path-to-javac --></executable>
<compilerVersion>1.8.31</compilerVersion>
</configuration>
</plugin>
- 这是正确的代码吗?
- 它应该替换当前代码,还是应该将它添加到 xml 中?
谢谢!
最佳答案
您走在正确的轨道上,但只需覆盖您需要的选项即可。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
...
</plugins>
</build>
不需要重复 verbose、fork、executable 等。
关于java - 在eclipse maven项目中设置jdk版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32996065/