Home > Net >  Maven build fails through Eclipse with Java 7
Maven build fails through Eclipse with Java 7

Time:12-02

I've set up a new Maven project webapp with Eclipse 2022-06 (4.24.0) which has Maven 3.8.4 embedded. According to the enter image description here

Furthermore, if I configure a new maven runtime with Maven 3.6.2, external of eclipse, I can compile with Java 1.7 and Java 1.8.

This is my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.company</groupId>
    <artifactId>hello-world</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>hello-world Maven Webapp</name>
    <!-- FIXME change it to the project's website -->
    <url>http://www.example.com</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>

    <build>
        <finalName>hello-world</finalName>
        <pluginManagement>
            <!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>3.2.2</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

So, it's a eclipse bug? or isn´t really compatible Maven 3.8.4 with Java 7? Or I missing any extra config?

Thank you!

CodePudding user response:

The error comes from a class from Google Guava. That's used by Maven - org.apache.maven:maven-core has a dependency on com.google.inject:guice which has a dependency on com.google.guava:guava. The Guava used by maven-core 3.8.4 and 3.8.6 is 25.1-android, which is built to be compatible with Java 7. My guess is that Eclipse comes with a newer version of Guava which somehow overrides the version used by Maven.

  • Related