0

I have just created a Spring Boot Maven Application with Kotlin and MongoDB in IntelliJ. The Maven command build mvn clean install fails to run maven-surefire-plugin tests and generates error SurefireBooterForkException:

Error while executing forked tests.Error while executing process.Cannot run program "/bin/sh": error=2, No such file or directoryorg.apache.maven.surefire.shade.common.org.apache.maven.shared.utils.cli.CommandLineException: Error while executing process.

My pom.xml file:

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.project</groupId>
    <artifactId>project-backend</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>project-backend</name>
    <description>Backend for project</description>
    <properties>
        <java.version>11</java.version>
        <kotlin.version>1.6.10</kotlin.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.module</groupId>
            <artifactId>jackson-module-kotlin</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-reflect</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib-jdk8</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
        <testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${project.parent.version}</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M1</version>
            </plugin>
            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <configuration>
                    <args>
                        <arg>-Xjsr305=strict</arg>
                    </args>
                    <compilerPlugins>
                        <plugin>spring</plugin>
                    </compilerPlugins>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.jetbrains.kotlin</groupId>
                        <artifactId>kotlin-maven-allopen</artifactId>
                        <version>${kotlin.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

</project>

I have tried the following:

  • mvn clean install -U or right-click on "project" Go to "Maven" >> "Update"
  • Enabling the system classloader in maven-surefire-plugin

I'm new to Spring Boot, Maven and IntelliJ.

UPDATE: I added the following to maven-surefire-plugin:

<configuration>
        <forkCount>0</forkCount>
</configuration>

Then the Maven build is successful. Why is this working??

Masoud Keshavarz
  • 2,166
  • 9
  • 36
  • 48
Ingvild
  • 1
  • 1
  • 1

1 Answers1

0

Probably it's just a bug, as said here.

As documentation says

The parameter forkCount defines the maximum number of JVM processes that maven-surefire-plugin will spawn concurrently to execute the tests.

So, to resolve the issue, try to choose another JDK or downgrade your JDK or use the solution you specified.

tohhant
  • 103
  • 10
  • Thank you! I downgraded my JDK so that maven builds, but I get the following error when running my tests: "project/projectbackend/service/ProjectServiceTest has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0" – Ingvild Mar 30 '22 at 08:36
  • @Ingvild, try to recompile tests with downgraded JRE – tohhant Apr 02 '22 at 07:05