45

I get the following error

BUILD ERROR
Error occured in starting fork, check output in log

when using Maven 2.2.1 and Surefire plugin 2.11 while running junit test cases.

How can I fix it?

Michael
  • 41,989
  • 11
  • 82
  • 128
user1137387
  • 1,933
  • 3
  • 18
  • 27

3 Answers3

34

You need to setup surefire plugin to use <forkMode>once</forkMode> like this:

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.5</version>
            <configuration>
                <skipTests>false</skipTests>
                <testFailureIgnore>true</testFailureIgnore>
                <forkMode>once</forkMode>
            </configuration>
</plugin>
dr0i
  • 2,380
  • 2
  • 19
  • 36
user1137387
  • 1,933
  • 3
  • 18
  • 27
  • the option is deprecated, any updated combination to solve the issue? – Naman Aug 30 '17 at 04:03
  • 24
    I fixed it with 0 (instead of the deprecated forkMode). – Alban Mar 29 '18 at 10:16
  • 1
    notice that forkMode once is NOT the same as forkCount 0.From https://maven.apache.org/surefire/maven-surefire-plugin/examples/fork-options-and-parallel-execution.html, the equivalent would be forkCount 1 with reuseForks true. However, seems forkCount 0 fixes the issue. – Simon Ninon Jul 18 '18 at 06:00
  • 2
    with this you loose jacoco coverage on sonar...any other ideas because i m in the same situation. thanks – Mançaux Pierre-Alexandre Jan 08 '21 at 16:47
4

I was facing the same issue on my local with maven-surefire-plugin plugin.

After adding <forkCount>0</forkCount> to maven-surefire-plugin plugin it worked for me.

        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <argLine>-Xmx1024m -XX:MaxPermSize=256m ${surefireArgLine}</argLine>
                <includes>
                    <include>**/*Test.java</include>
                </includes>
                <forkCount>0</forkCount>
            </configuration>
        </plugin>
Ganesh Thorat
  • 492
  • 1
  • 7
  • 19
-1

encountered the same issue

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.1</version>
    <configuration>
        <useSystemClassLoader>false</useSystemClassLoader>
    </configuration>
</plugin>  

set "useSystemClassLoader as false"

Abhishek D K
  • 2,257
  • 20
  • 28