What causes imported Maven project in Eclipse to use Java 1.5 instead of Java 1.6 by default and how can I ensure it doesn't?

前端 未结 13 2188
情深已故
情深已故 2020-11-27 09:51

I imported a Maven project and it used Java 1.5 even though I have 1.6 configured as my Eclipse default Preferences->Java->Installed JREs.

When I

13条回答
  •  广开言路
    2020-11-27 10:14

    In case anyone's wondering why Eclipse still puts a J2SE-1.5 library on the Java Build Path in a Maven project even if a Java version >= 9 is specified by the maven.compiler.release property (as of October 2020, that is Eclipse version 2020-09 including Maven version 3.6.3): Maven by default uses version 3.1 of the Maven compiler plugin, while the release property has been introduced only in version 3.6.

    So don't forget to include a current version of the Maven compiler plugin in your pom.xml when using the release property:

    
        15
    
    
    
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                3.8.1
            
        
    
    

    Or alternatively but possibly less prominent, specify the Java version directly in the plugin configuration:

    
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                3.8.1
                
                    15
                
            
        
    
    

    This picks up Line's comment on the accepted answer which, had I seen it earlier, would have saved me another hour of searching.

提交回复
热议问题