Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Surefire test failed: Unsupported class file major version 61

I am trying to create a project in IntelliJ using Maven, but when running mvn install or mvn test in order to run the simple JUnit tests I wrote, it fails with the following error:

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project Idlearn: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test failed: Unsupported class file major version 61 -> [Help 1]

My pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project>
    <modelVersion>4.0.0</modelVersion>

    <groupId>mimuw</groupId>
    <artifactId>Idlearn</artifactId>
    <version>1</version>
    <name>Idlearn</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <!-- for platform independent encoding-->
        <junit.version>5.8.2</junit.version> <!-- the latest JUnit version -->
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>${junit.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>17</source>
                    <target>17</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

I feel like I have tried every possible solution on the web, but to no avail.

The problem originally was that my tests wouldn't run. The command mvn test would output that it was running SomeClassTest however not run any actual tests that it contained (all created just like in many tutorials I found on-line). It seems like I was missing maven-surefire and here I am now.

like image 533
Maurycyt Avatar asked Jan 29 '26 09:01

Maurycyt


1 Answers

This is what worked for me using Java 17.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.ow2.asm</groupId>
            <artifactId>asm</artifactId>
            <version>9.1</version>
        </dependency>
    </dependencies>
</plugin>

And when upgrading to Java 18 this morning, I had to upgrade to asm v9.3 as well.

I hope it helps.

like image 151
Salathiel Genèse Avatar answered Jan 30 '26 23:01

Salathiel Genèse