Build failing on sonar


With Maven 3+ we may face some issues while running sonar code coverage for the project in surefire plugin.
Looks line may be bug in maven or surefire, can't say right now.
Here is one of the weird error I have observed


Exception in thread "main" java.lang.NoClassDefFoundError: ${surefire/jvm/args}Caused by: java.lang.ClassNotFoundException: ${surefire.jvm.args} at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247)Could not find the main class: ${surefire.jvm.args}.  Program will exit.

It took really long time and lots of effort to figure out the solution for this error.
sonar goal is expecting an argument as default but failed to get and hence its throwing error.

You will need to add one extra configuration (argLine) under build section in your pom file for surefire plugin.

Please add following section in your pom to fix this error.

<build>
    <plugins>
        <plugin>

            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <argLine>-Xmx1024m</argLine>
            </configuration>
        </plugin>
    </plugins>
</build>


Here i have just mentioned the argLine=-Xmx1024m (1GB of memory), you can add any dummy argument to make build pass.

May be recent version of maven/surefire may have fixed this issue.

Popular posts from this blog

Manage Docker images on local disk

Gradle or Maven - A Dilemma

Setup Docker slaves for Jenkins