A. Vreeswijk
A. Vreeswijk

Reputation: 954

Maven upgrade source version

I have a problem. I installed Java 15.0.2 on my Ubuntu machine:

java version "15.0.2" 2021-01-19
Java(TM) SE Runtime Environment (build 15.0.2+7-27)
Java HotSpot(TM) 64-Bit Server VM (build 15.0.2+7-27, mixed mode, sharing)

I also installed maven:

Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 15.0.2, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-15-oracle
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-66-generic", arch: "amd64", family: "unix"

Now When I am trying to build the package, I get the following errors:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project Simulator: Compilation failure: Compilation failure:
[ERROR] /binance/Simulator/src/main/java/com/company/drivers/SimulatorDriver.java:[241,16] switch expressions are not supported in -source 7
[ERROR]   (use -source 14 or higher to enable switch expressions)
[ERROR] /binance/Simulator/src/main/java/com/company/drivers/SimulatorDriver.java:[242,22] switch rules are not supported in -source 7
[ERROR]   (use -source 14 or higher to enable switch rules)
[ERROR] /binance/Simulator/src/main/java/com/company/models/Candlestick.java:[127,43] method references are not supported in -source 7
[ERROR]   (use -source 8 or higher to enable method references)
[ERROR] /binance/Simulator/src/main/java/com/company/models/Candlestick.java:[175,155] lambda expressions are not supported in -source 7
[ERROR]   (use -source 8 or higher to enable lambda expressions)
[ERROR] /binance/Simulator/src/main/java/com/company/models/Slope.java:[63,38] method references are not supported in -source 7
[ERROR]   (use -source 8 or higher to enable method references)
[ERROR] /binance/Simulator/src/main/java/com/company/models/Slope.java:[94,155] lambda expressions are not supported in -source 7
[ERROR]   (use -source 8 or higher to enable lambda expressions)
[ERROR] /binance/Simulator/src/main/java/com/company/models/Pattern.java:[76,35] method references are not supported in -source 7
[ERROR]   (use -source 8 or higher to enable method references)
[ERROR] /binance/Simulator/src/main/java/com/company/models/Pattern.java:[102,155] lambda expressions are not supported in -source 7
[ERROR]   (use -source 8 or higher to enable lambda expressions)
[ERROR] /binance/Simulator/src/main/java/com/company/deserializers/AgentStrategyConfigDeserializer.java:[21,163] lambda expressions are not supported in -source 7
[ERROR]   (use -source 8 or higher to enable lambda expressions)
[ERROR] /binance/Simulator/src/main/java/com/company/deserializers/AgentStrategyPackageDeserializer.java:[27,163] lambda expressions are not supported in -source 7
[ERROR]   (use -source 8 or higher to enable lambda expressions)

It looks like that the Java version in Maven is 7, but I need to run at version 15. I already installed java, but how can I upgrade/set the java for my maven?

Upvotes: 1

Views: 740

Answers (2)

Kristof Neirynck
Kristof Neirynck

Reputation: 4162

You could add these properties in your pom.xml:

<properties>
    <maven.compiler.source>15</maven.compiler.source>
    <maven.compiler.target>15</maven.compiler.target>
    <maven.compiler.release>15</maven.compiler.release>
    <java.version>15</java.version>
</properties>

Upvotes: 1

J Fabian Meier
J Fabian Meier

Reputation: 35843

Try to add the following to your POM

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
        <release>15</release>
    </configuration>
</plugin>

Upvotes: 3

Related Questions