Maven 3, Windows 7, JDK1.7.0_51
I have the following very simple Maven POM
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.gwl</groupId>
<artifactId>test-lineseparator</artifactId>
<version>0.0.1-SNAPSHOT</version>
</project>
and the following very simple test class
public class TestLineSeparator {
public static void main(String[] args) {
System.out.print("This is a line using System.lineSeparator()." + System.lineSeparator());
}
}
- I have jdk1.7.0_51 installed as my default build environment.
- The default src and target args for the Maven compiler plugin are 1.5.
- The System.lineSeparator() method was not introduced until 1.7
Maven compiles the code without issue. It will run OK under a 1.7 JRE/JDK, but 1.6 or earlier complains
Exception in thread "main" java.lang.NoSuchMethodError: java.lang.System.lineSeparator()Ljava/lang/String;
Q. Why does Maven not complain about System.lineSeparator() not existing when its compiler src argument defaults to 1.5?
(Note, the same question applies to an Eclipse projected generated from the same POM. Despite 1.5 Compiler Compliance and a 1.5 Execution Environment being set, there are no complaints)