Unable to compile simple Java 10 / Java 11 project with Maven

前端 未结 7 944
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 14:31

I have a trivial Maven project:

src
└── main
    └── java
        └── module-info.java
pom.xml

pom.xml:

org.         


        
7条回答
  •  佛祖请我去吃肉
    2020-11-22 14:41

    Specify maven.compiler.source and target versions.

    1) Maven version which supports jdk you use. In my case JDK 11 and maven 3.6.0.

    2) pom.xml

    
        11
        11
    
    

    As an alternative, you can fully specify maven compiler plugin. See previous answers. It is shorter in my example :)

    
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                3.8.0
                
                    11
                
            
        
    
    

    3) rebuild the project to avoid compile errors in your IDE.

    4) If it still does not work. In Intellij Idea I prefer using terminal instead of using terminal from OS. Then in Idea go to file -> settings -> build tools -> maven. I work with maven I downloaded from apache (by default Idea uses bundled maven). Restart Idea then and run mvn clean install again. Also make sure you have correct Path, MAVEN_HOME, JAVA_HOME environment variables.

    I also saw this one-liner, but it does not work.

    11
    

    I made some quick starter projects, which I re-use in other my projects, feel free to check:

    • https://github.com/yan-khonski-it/mvn-pmd-java11
    • https://github.com/yan-khonski-it/pmd-java-14

提交回复
热议问题