3

I have weird problem that mvn clean test fails only when I try to add module-info.java to my project using Spring Boot. Project structure is very simple

    │   pom.xml
    │
    ├───.idea
    │       .gitignore
    │       compiler.xml
    │       encodings.xml
    │       jarRepositories.xml
    │       misc.xml
    │       workspace.xml
    │
    └───src
        ├───main
        │   ├───java
        │   │   │   module-info.java
        │   │   │
        │   │   └───com
        │   │       └───test
        │   └───resources
        └───test
            ├───java
            │   └───com
            │       └───test
            │               SomeTest.java
            │
            └───resources

SomeTest.java is very simple


import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class SomeTest {
    @Test
    public void test() {
        var isTrue = true;
        Assertions.assertTrue(isTrue);
    }
}

module-info.java also:

open module com.test {
}

pom.xml file is taken from sprint initalizr

<?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">
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.test</groupId>
    <artifactId>SampleTest</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
    
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

And now the weird thing is that when module-info.java file is present then mvn clean test fails Unsupported class file major version 61

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project SampleTest: 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]

but when I delete module-info.java then everything goes without error. Any ideas how can I achieve java modules with spring boot? :)

4
  • What does mvn --version tell you? Are you running on plain command line? Commented Oct 6, 2021 at 18:02
  • Please do not use images: meta.stackoverflow.com/q/285551/296328 Commented Oct 6, 2021 at 18:17
  • @khmarbaise maven version is 3.8.3 mvn --version Apache Maven 3.8.3 (...) Maven home: X:\apache-maven-3.8.3 Java version: 17, vendor: Oracle Corporation, runtime: X:\Java\jdk-17 Default locale: pl_PL, platform encoding: Cp1250 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows" Commented Oct 6, 2021 at 19:10
  • Also added the error as code for to be better indexed :) Commented Oct 6, 2021 at 19:13

2 Answers 2

6

You have to overwrite the used maven-surefire-plugin version because the version defined by spring boot parent is too old.

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M5</version>
            </plugin>
        </plugins>
    </pluginManagement>
...
Sign up to request clarification or add additional context in comments.

1 Comment

That does the trick! Thank you! :)
0

For the problem after migration to reactive webflux with spring-boot 3, theblockhound-junit-platform.version version must be updated. For Spring-boot 3.2, I used:

<dependency>
            <groupId>io.projectreactor.tools</groupId>
            <artifactId>blockhound-junit-platform</artifactId>
            <version>1.0.8.RELEASE</version> <!-- It was 1.0.4.RELEASE -->
            <scope>test</scope>
        </dependency>

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.