Does maven compiler plugin with source 1.6 configuration recognise API introduced since 1.7?

后端 未结 1 1759
感情败类
感情败类 2021-01-15 05:25

I\'ve a maven project with the maven-compiler-plugin configured as below:

    
      maven-compiler-plugin         


        
相关标签:
1条回答
  • 2021-01-15 06:19

    Neither target nor source relate in any way to what classes are available on the compiler's classpath. If you're compiling your code with the 1.7 compiler then any classes that shipped with 1.7 will be available to your code.

    What target does is tell the compiler to output .class files in a format that is compatible with the 1.6 release of java. source says only accept java code that would compile with the 1.6 version of the compiler.

    So it's perfectly legitimate to make a call to a class that shipped only on 1.7 or later using Java 1.6 compatible source code written into a class file that is compatible with Java 1.6. It just won't run on 1.6.

    The only way to ensure your code will run on 1.6 (if that's what you're trying to do) is to use a 1.6 JDK to compile your project.

    0 讨论(0)
提交回复
热议问题