[Solved] lambda expressions are not supported in -source 1.7 [ERROR] (use -source 8 or higher to enable lambda expressions)

Q: lambda expressions are not supported in -source 1.7 [ERROR] (use -source 8 or higher to enable lambda expressions)

Answer:

You are getting this error because you are using below Java version 8 and Lambda came in Java 8

Method 1: to solve this issue add java 8 configuration with maven-compiler-plugin.

  1. <project>
  2. [...]
  3. <build>
  4. [...]
  5. <plugins>
  6. <plugin>
  7. <groupId>org.apache.maven.plugins</groupId>
  8. <artifactId>maven-compiler-plugin</artifactId>
  9. <version>3.7.0</version>
  10. <configuration>
  11. <source>1.8</source>
  12. <target>1.8</target>
  13. </configuration>
  14. </plugin>
  15. </plugins>
  16. [...]
  17. </build>
  18. [...]
  19. </project>

Method 2: Add Java 8 as Maven Properties

pom.xml

    <properties>        <maven.compiler.target>1.8</maven.compiler.target>        <maven.compiler.source>1.8</maven.compiler.source>    </properties>