spaghetti_code
spaghetti_code

Reputation: 145

Maven build failure

I'm trying to build a maven application, but I get an error message:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project helloworld: Compilation failure

[ERROR] D:...\Spark-test\java-getting-started\src\main\java\Main.java:[73,35] error: lambda expressions are not supported in -source 1.5

It's a heroku example java project, and in the system.properties file the java version is set: java.runtime.version=1.8

The specific lines are these:

get("/login", (request, response) -> {
   System.out.println("request: " + request);
   return "Hello World From Spark";
});

I don't understand where would be the problem, or where is set the source to java 1.5

Upvotes: 1

Views: 6676

Answers (1)

Kuurde
Kuurde

Reputation: 885

Try adding this to your pom.xml:

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

Somehow maven tries to compile against java 1.5, which did not have lambdas yet (only since 1.8). How are you starting the build? Maven command line or an IDE?

Edit: alternative way, simply set these properties:

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

source

Upvotes: 8

Related Questions