Why did Maven Update Project JDK change back to 1.5

1. Problem description 

            Create a new Maven project in Eclipse, and then change the JDK version to 1.6. As a result, every time you use Maven > Update project, the JDK version is restored to 1.5.

 

Second, cause analysis

          The official Maven documentation has the following description:

 

The compiler plugin is used to compile the source files of the project. Since version 3.0, 

The default compiler used to compile Java source files is javax.tools.JavaCompiler (if you are using java 1.6). 

 

If you want to force the plugin to use javac, you must configure the plugin option forceJavacCompilerUse.  

At the same time, it should be noted that the default settings of the source option and the target option are currently 1.5, regardless of the JDK version when running Maven.

 

If you want to change these default settings, set the source and target options as described in Setting the -source and -target of the Java Compiler.

 

          This is a known feature of Maven. Unless you specify a version explicitly in your POM file, the compiler default source/target version 1.5 will be used. The main reason is that the integration of Maven in Eclipse plays a key role. It generates the .project, .classpath and .settings of the project from the POM file, so unless the POM file specifies the correct JDK version, you update the project configuration every time when it resets to version 1.5. 

 

 

3. Solutions

 

We can force it to specify it in the pom

 
< plugins >
   < plugin >
         < groupId >org.apache.maven.plugins</ groupId >
         < artifactId >maven-compiler-plugin</ artifactId >
         < version >3.5.1</ version >
         < configuration >
             < source >1.7</ source >

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326602750&siteId=291194637