compilation failure for spring boot application with java 9 and maven

前端 未结 3 1048
醉话见心
醉话见心 2020-12-18 11:24

I am trying to build spring-boot application that uses java-9 and would be deployed to heroku. As a build tool I use maven

3条回答
  •  孤城傲影
    2020-12-18 12:05

    Rightly pointed out by @Robert you need to update your maven-compiler-plugin. To add to it, also as stated in the Maven/Jigsaw+9 over the maven plugins. The minimum compatible version of maven-compiler-plugin with current jdk-9+181 is 3.6.2 which can be used as :

    
    
        org.apache.maven.plugins
        maven-compiler-plugin
        3.6.2
        
            
                9
            
        
    
    

    And to quote from one of the examples of maven-compiler-plugin with module-info.java here:

    For projects that want to be compatible with older versions of Java (i.e 1.8 or below), but also want to provide a module-info.java for Java 9 projects must be aware that they need to call javac twice: the module-info.java must be compiled with release=9, while the rest of the sources must be compiled with a lower version of source/target.

    which can be achieved using (JAVA_HOME set as 1.8.x) :

    
        org.apache.maven.plugins
        maven-compiler-plugin
        3.6.2
        
          
            default-compile
            
              
              
              
                9
              
              9
            
          
          
            base-compile
            
              compile
            
            
            
              
                module-info.java
              
            
          
        
        
        
          
          
            [1.5,9)
          
          1.5
          1.5
        
    
    

    Few things to note there though are:

    ... you will need at least Maven 3.3.1 to specify a custom jdkToolchain in your plugin configuration


    Or you can also configure the JAVA_HOME as /jdk9/Contents/Home/bin and use the following configuration:

    
        org.apache.maven.plugins
        maven-compiler-plugin
        3.6.2
        
          
            default-compile
            
              
              9
            
          
          
            base-compile
            
              compile
            
            
            
              
                module-info.java
              
            
          
        
        
        
          
          
            9
          
          6
        
    
    

提交回复
热议问题