CodexBloom - Programming Q&A Platform

Maven scenarios to execute `maven-surefire-plugin` with `UnsupportedClassVersionError` in multi-module project using Java 17

👀 Views: 61 đŸ’Ŧ Answers: 1 📅 Created: 2025-07-11
maven java-17 surefire-plugin multi-module Java

Can someone help me understand I'm dealing with I'm working with an `UnsupportedClassVersionError` when running tests with the `maven-surefire-plugin` in my multi-module Maven project that is built with Java 17..... The behavior message I'm receiving is: ``` Exception in thread "main" java.lang.UnsupportedClassVersionError: org/example/MyTest : Unsupported major.minor version 61.0 ``` This usually indicates that the compiled class version is higher than the version of the Java runtime. I have verified that my Maven compiler plugin is configured correctly in the parent `pom.xml`: ```xml <properties> <maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target> </properties> ``` However, when I try to run `mvn clean test`, the build process seems to default to an older version of Java (possibly Java 11) during the test phase. I have also set the `JAVA_HOME` environment variable to point to the JDK 17 installation, and I have added the following configuration in the `pom.xml` of my parent module: ```xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M5</version> </plugin> </plugins> </build> ``` I've checked my local Maven settings and don't see any overriding Java versions configured. I even ran `mvn -v` to confirm that Maven is picking up the correct JDK version: ``` Apache Maven 3.8.4 Maven home: /path/to/maven Java version: 17.0.2, vendor: Azul Systems, Inc. ``` Despite these checks, the tests still unexpected result with the same behavior. I suspect it might have something to do with how the modules are configured, or perhaps there's a mismatch in the JDK setup for the individual modules. Can anyone provide insights on how to resolve this scenario? I'm working on a web app that needs to handle this. My development environment is Windows 11. Thanks in advance!