简体   繁体   中英

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.

The following settings are modified by Maven:

Settings | Compiler | Java Compiler -> Target bytecode version

在此输入图像描述

And Project Settings | Modules -> Language Level

在此输入图像描述

Why is this happening and what do I have to do, so that maven doesn't vandalise my settings?

You have to explicitely set the java version in your pom file so that version 1.5 doesn't get set by default.

<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-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

       <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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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