25

This morning Maven starts complaining with this error:

error: multi-catch statement is not supported in -source 1.5

Oddly, I'm using JDK 7 and this code has been building fine for weeks. I'm just using m2e with a default POM with no compiler versions specified.

Here's my Maven version information:

Apache Maven 3.0.2 (r1056850; 2011-01-08 19:58:10-0500)
Java version: 1.7.0_03, vendor: Oracle Corporation
Java home: C:\SDKs\Java\jdk1.7.0_03\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"

I can get around it by using the Maven compiler plugin like so:

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

Still, I'd like to understand why Maven would suddenly start misbehaving and requiring the use of the compiler plugin.

2
  • 2
    You are always using the maven-compiler-plugin. This is just configuring it.
    – bmargulies
    May 14, 2012 at 15:33
  • Possible the maven-compiler-plugin is not configured right and not picked by maven.
    – prayagupa
    Jun 27, 2021 at 18:00

3 Answers 3

14

The default source/target levels are 1.5, which doesn't support Java 1.7 syntax, obviously.

As to why it would "suddenly" change, something changed in your m2e or project configuration.

13

Most likely this is a problem with your environment, not maven (ie, your JAVA_HOME environmental variable changed). It's worth noting that the compiler plugin is required anyway. By including this compiler section in your pom you are ensuring that your code gets compiled with the correct compiler, regardless of your environmental settings.

0

You can also resolve this problem by using below steps for Eclips user and can be work for IntelliJ as well-

Right click on the project and select Buid Path then Configure Build Path.. Select Project Facets under Maven. Then select Java version as 1.8 and apply ok.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.