4

I have added the source target below into pom.xml.

<?xml version="1.0" encoding="UTF-8"?>
<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>priv.winnie</groupId>
  <artifactId>newfeature</artifactId>
  <version>1.0-SNAPSHOT</version>

<dependencies>
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.10</version>
  </dependency>
</dependencies>

  <build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.1</version>
      <configuration>
        <source>1.8</source>
        <target>1.8</target>
      </configuration>
    </plugin>
  </plugins>
  </build>
</project>

I have also changed the Java compiler to 1.8 within IntelliJ. I'm running OpenJDK 1.8.0.

Why it still using Java source level 1.5 to compile code?

Makoto
  • 104,088
  • 27
  • 192
  • 230
xksyvone
  • 105
  • 1
  • 12
  • Please show you full pom file and the full log output...Furthermore check on console first to exclude influences of your IDE... – khmarbaise Jul 22 '17 at 11:48
  • @khmarbaise Pasted my pom.xml in my answer. And it shows red wavy line on "import java.util.function.Consumer;" in the class file. – xksyvone Jul 22 '17 at 15:12
  • Are you getting the error from a Maven goal (like `mvn clean compile`) or from within IntelliJ? – Makoto Jul 22 '17 at 15:21
  • I see this red wavy line in Intellij with maven plugin. It is abnormal, so i hit this compile issue when execute 'run' in Intellij IDE. – xksyvone Jul 22 '17 at 15:31
  • As mentioned please check your complete build on plain command line first to exclude influences of the IDE first... – khmarbaise Jul 22 '17 at 15:50

2 Answers2

3

go to project property > java compiler and check there, jdk version.

enter image description here

Anshul Sharma
  • 3,432
  • 1
  • 12
  • 17
1

Fixed this issue. I found it was unnecessary to add java1.8 into pom.xml. I just need to change the Modules->language level into 8 - Lambdas,type annotations etc.

xksyvone
  • 105
  • 1
  • 12