How to make maven cobertura and surefire plugins work together?
Asked Answered
H

2

8

I put the surefire and cobertura plugins in my pom.xml, but I can't configure them to work fine. Or cobertura doesn't run or the tests are executes twice.

So, how could I configure the plugins for they run together and just one time?

If I configure in this way, cobertura doesn't run:

<plugin>
<groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
    <version>2.12</version>
</plugin>

If I configure in this way, the tests are executes twice:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-maven-plugin</artifactId>
    <version>2.5.1</version>
    <executions>
        <execution>
            <phase>test</phase>
            <goals>
                <goal>cobertura</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.12</version>
</plugin>
Hutchison answered 17/2, 2012 at 1:55 Comment(4)
What maven goal(s) are you running?Schroder
An alternative is to use Sonar. Runs both these tools with no need to alter your POM file (Plugin is driven by properties, which you can set in your settings file.)Rusel
I've added a part of my pom.xml in the topicHutchison
You can have a look at this : #733495Leslielesly
S
0

The tests will run twice - it is just the way it is. See Samuel's comment running junits and cobertura with maven

Stephanistephania answered 1/5, 2014 at 0:26 Comment(0)
B
0

This is how I got it to work for tests with cobertura on and surefire off. Add this to your pom, or put in mvn options for -DuseSystemClassLoader=false

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
                <useSystemClassLoader>false</useSystemClassLoader>
                <testFailureIgnore>true</testFailureIgnore>
            </configuration>
        </plugin>
Brume answered 11/2, 2019 at 17:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.