Search code examples
javaeclipsemavenjava-8java-7

Maven build fails through Eclipse with Java 7


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 Maven release notes info requires Java 1.7.

If I do a package with Java 1.7, the build fails with an error that indicates that need Java 1.8:

Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
Maven home: D:\Proyectos\java\hello-world\eclipse\workspace\hello-world\EMBEDDED
Java version: 1.7.0_79, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.7.0_79\jre
Default locale: es_ES, platform encoding: UTF-8
OS name: "windows 8.1", version: "6.3", arch: "amd64", family: "windows"
---------------------------------------------------
constituent[0]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/
constituent[1]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/maven-core-3.8.4.jar
constituent[2]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/maven-model-3.8.4.jar
constituent[3]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/maven-settings-3.8.4.jar
constituent[4]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/maven-settings-builder-3.8.4.jar
constituent[5]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/maven-builder-support-3.8.4.jar
constituent[6]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/maven-repository-metadata-3.8.4.jar
constituent[7]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/maven-artifact-3.8.4.jar
constituent[8]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/maven-plugin-api-3.8.4.jar
constituent[9]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/maven-model-builder-3.8.4.jar
constituent[10]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/maven-resolver-provider-3.8.4.jar
constituent[11]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/maven-resolver-api-1.6.3.jar
constituent[12]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/maven-resolver-spi-1.6.3.jar
constituent[13]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/maven-resolver-util-1.6.3.jar
constituent[14]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/maven-shared-utils-3.3.4.jar
constituent[15]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/commons-io-2.6.jar
constituent[16]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/org.eclipse.sisu.inject-0.3.5.jar
constituent[17]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/guice-4.2.2-no_aop.jar
constituent[18]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/plexus-utils-3.3.0.jar
constituent[19]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/plexus-interpolation-1.26.jar
constituent[20]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/plexus-component-annotations-2.1.0.jar
constituent[21]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/commons-lang3-3.8.1.jar
constituent[22]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/maven-embedder-3.8.4.jar
constituent[23]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/javax.annotation-api-1.2.jar
constituent[24]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/plexus-sec-dispatcher-2.0.jar
constituent[25]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/plexus-cipher-2.0.jar
constituent[26]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/commons-cli-1.4.jar
constituent[27]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/maven-compat-3.8.4.jar
constituent[28]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/wagon-provider-api-3.4.3.jar
constituent[29]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/org.eclipse.sisu.plexus-0.3.5.jar
constituent[30]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/aether-connector-okhttp-0.17.8.jar
constituent[31]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/okhttp-3.14.1.jar
constituent[32]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/okio-1.17.3.jar
constituent[33]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/maven-resolver-impl-1.6.3.jar
constituent[34]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/maven-resolver-connector-basic-1.6.3.jar
constituent[35]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/maven-resolver-transport-wagon-1.6.3.jar
constituent[36]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/wagon-file-3.4.3.jar
constituent[37]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime_1.18.3.20220227-1319/jars/jansi-2.4.0.jar
constituent[38]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime.slf4j.simple_1.18.1.20211008-0657/
constituent[39]: file:/D:/Proyectos/java/hello-world/eclipse/plugins/org.eclipse.m2e.maven.runtime.slf4j.simple_1.18.1.20211008-0657/jars/slf4j-simple-1.7.30.jar
constituent[40]: file:/D:/Proyectos/java/hello-world/eclipse/configuration/org.eclipse.osgi/9/0/.cp/
constituent[41]: file:/D:/Proyectos/java/hello-world/eclipse/configuration/org.eclipse.osgi/879/0/.cp/
constituent[42]: file:/D:/Proyectos/java/hello-world/eclipse/configuration/org.eclipse.osgi/30/0/.cp/
---------------------------------------------------
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/google/common/collect/ImmutableSet : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:425)
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
    at com.google.inject.internal.Errors.<clinit>(Errors.java:105)
    at com.google.inject.internal.InternalInjectorCreator.<init>(InternalInjectorCreator.java:61)
    at com.google.inject.Guice.createInjector(Guice.java:87)
    at com.google.inject.Guice.createInjector(Guice.java:69)
    at com.google.inject.Guice.createInjector(Guice.java:59)
    at org.codehaus.plexus.DefaultPlexusContainer.addPlexusInjector(DefaultPlexusContainer.java:481)
    at org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:206)
    at org.apache.maven.cli.MavenCli.container(MavenCli.java:651)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:196)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)

But, if I change the JRE compiler to 1.8, the build is success: 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!


Solution

  • 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.