kar
kar

Reputation: 3651

Build failing due to version only via terminal

I have a simple maven project which builds fine and runs in Intellij. The Java version is set to version 8 under relevant settings in Intellij.

Under the maven POM file, I have set the following to point to the java version.

<modelVersion>4.0.0</modelVersion>

    <properties>
        <java.version>1.8</java.version>
        <javac.src.version>1.8</javac.src.version>
        <javac.target.version>1.8</javac.target.version>
    </properties>

    <groupId>org.example</groupId>
    <artifactId>exa</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
    .....

My maven version and info as follows:

Maven home: C:\Users\name\apache-maven-3.6.3\bin\..
Java version: 1.8.0_231, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_231\jre

As mentioned, no issues when run via Intellij. But when I run maven commands via the intellij terminal or normal terminal, I get following error.

Example Maven commands.

mvn clean package
or
mvn verify 

Error:

COMPILATION ERROR
/C:/Users/name/projectname/src/main/java/pack/Main.java:[17,51] method references are not supported in -source 1.5

I don't even have java sdk 1.5 on my machine. Can I get some help on where I should change this version to 8 so I can make a maven build please? Thanks.

Upvotes: 0

Views: 37

Answers (1)

Govinda Sakhare
Govinda Sakhare

Reputation: 5749

In your project's pom.xml, it seems the source is configured to java 1.5. Make sure the correct source version is configured in pom.xml.

If you are using maven-compiler-plugin, change the version as below.

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

or

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

Upvotes: 2

Related Questions