4

I am using maven site plugin and cobertura together to run unit tests and generate report. Everything is working fine , but only problem is all unit tests are running twice.

I tried to set forkMode as never for maven-site-plugin but even then I am facing the same problem.

Any help would be appreciated.

My command: mvn cobertura:cobertura -Dcobertura.report.format=html

My pom:

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <configuration>
                    <aggregate>true</aggregate>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <configuration>
                    <aggregate>false</aggregate>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>findbugs-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
            </plugin>
        </plugins>
    </pluginManagement>

    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<reporting>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <configuration>
                <formats>
                    <format>html</format>
                    <format>xml</format>
                </formats>
                <instrumentation>
                    <excludes>
                        <exclude>**/test/**/*.class</exclude>
                    </excludes>
                </instrumentation>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-pmd-plugin</artifactId>
            <version>3.0.1</version>
            <configuration>
                <targetJdk>1.6</targetJdk>
                <linkXref>true</linkXref>
                <sourceEncoding>ISO-8859-1</sourceEncoding>
                <format>xml</format>
                <aggregate>true</aggregate>
                <verbose>true</verbose>
                <rulesets>
                    <ruleset>favorites.xml</ruleset>
                </rulesets>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.9.1</version>
            <configuration>
                <aggregate>true</aggregate>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>findbugs-maven-plugin</artifactId>
            <version>2.5.2</version>
            <configuration>
                <xmlOutput>true</xmlOutput>
            </configuration>
        </plugin>
    </plugins>
</reporting>
Saravanan S
  • 1,021
  • 1
  • 10
  • 24
  • 1
    possible duplicate of [running junits and cobertura with maven](http://stackoverflow.com/questions/732995/running-junits-and-cobertura-with-maven) – Artjom B. Sep 21 '15 at 21:24

3 Answers3

0

I believe this is a normal behaviour.

You are using two distinct reports which bases on the same thing :

  • the test report requires the test to be run but does not enable coverage.
  • the coverage report requires the test to be run with coverage.

But both reports does not know of each other, that why it is run twice.

[UPDATE] after reading this mailing list, it says that you should disable the test (using skipTests) preferably in a profile.

As for your command line, it would give:

mvn cobertura:cobertura -DskipTests -Dcobertura.report.format=html

Note however that I could not get cobertura working (got Encountered " "final" "final "" at line 106, column 12.) with my project, so I don't know if it worked.

NoDataFound
  • 11,381
  • 33
  • 59
  • Yes. You may be correct. But Is there a way to avoid this? In some forums it is mentioned that "forkmode" can be added as a configuration to avoid this. But that is not working for me. – Saravanan S Aug 20 '14 at 23:18
0

I ended up in creating 2 profiles, one for cobertura and another for site, which will build findbugs, CPD and PMD analysis. Not sure if this is the correct way, but solves my problem.

Hope this will be helpful for somebody.

Saravanan S
  • 1,021
  • 1
  • 10
  • 24
0

Tests will always be run twice with the cobertura-maven-plugin.

If you need cobertura reports and want tests to be run only once, you can try the qualinsight-mojo-cobertura-core plugin. You'll find the documentation on the project's page: https://github.com/QualInsight/qualinsight-mojo-cobertura .

Kraal
  • 2,779
  • 1
  • 19
  • 36
  • Please don't post the exact same answer to multiple questions. Instead select the best question and post your answer there, then you can flag the worse questions as duplicates of the better one. If they are not duplicates then you need to change each answer so that it answers *that specific question*. I voted to close this question as a duplicate of the original question: [running junits and cobertura with maven](http://stackoverflow.com/questions/732995/running-junits-and-cobertura-with-maven). – Artjom B. Sep 21 '15 at 21:34