简体   繁体   English

Maven更新重置Java版本

[英]Maven update resets Java version

Everytime I modify the dependencies inside the pom.xml file in my IntelliJ Maven project, the Java version is set to 1.5 and I have to receonfigure my project. 每次我在IntelliJ Maven项目中修改pom.xml文件中的依赖项时,Java版本都设置为1.5 ,我必须重新配置我的项目。

The following settings are modified by Maven: Maven修改了以下设置:

Settings | Settings | Compiler | Compiler | Java Compiler -> Target bytecode version Java Compiler - > Target bytecode version

在此输入图像描述

And Project Settings | Project Settings | Modules -> Language Level Modules - > Language Level

在此输入图像描述

Why is this happening and what do I have to do, so that maven doesn't vandalise my settings? 为什么会发生这种情况,我该怎么做,以便maven不会破坏我的设置?

You have to explicitely set the java version in your pom file so that version 1.5 doesn't get set by default. 您必须在pom文件中明确设置java版本,以便默认情况下不会设置版本1.5。

<project>
 [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
    [...]
  </build>
  [...]
</project>

Specify the java version under properties . properties下指定java版本。

<properties>
        <java-version>1.8</java-version>
</properties>

and to use the same version with maven compile or package then include the same version in compile plug-in 并使用与maven编译或包相同的版本,然后在编译插件中包含相同的版本

       <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM