javamavenpom.xmlcloverclover-payment

Clover code coverage reporting showing zero in mvn sonar:sonar


When I run sonar my code coverage always coming 0. I am using clover. Below entry in pom.xml file

<properties>
        <java.version>11</java.version>
        <lombok.release>1.18.20</lombok.release>
        <spring-cloud.version>Hoxton.SR11</spring-cloud.version>
        <vigilphoenix-transformer-core.version>1.3-SNAPSHOT</vigilphoenix-transformer-core.version>
        <clover.version>4.2.0</clover.version>
        <sonar.java.coveragePlugin>clover</sonar.java.coveragePlugin>
        <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
        <sonar.clover.reportPath>target\site\clover\clover.xml</sonar.clover.reportPath>
    </properties>
    
    <plugin>
                <groupId>org.openclover</groupId>
                <artifactId>clover-maven-plugin</artifactId>
                <version>${clover.version}</version>
                <configuration>
                    <includesTestSourceRoots>false</includesTestSourceRoots>
                    <targetPercentage>0%</targetPercentage>
                    <debug>true</debug>
                </configuration>
                <executions>
                    <execution>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>setup</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>aggregate</id>
                        <phase>test</phase>
                        <goals>
                            <goal>clover</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.openclover</groupId>
                <artifactId>clover-maven-plugin</artifactId>
                <configuration>
                    <!--cloverDatabase>${project.build.directory}/target/clover/cloverMerge.db</cloverDatabase-->
                    <generateHtml>false</generateHtml>
                    <generatePdf>false</generatePdf>
                    <generateXml>true</generateXml>
                    <generateHistorical>false</generateHistorical>
                </configuration>
            </plugin>
        

When i run "mvn clean install" my clover.xml generate in "\target\site\clover\clover.xml"

Not sure what I have to do. if any one can help would be more help full.


Solution

  • You either need to configure the clover plugin which by default take that path or in your call for sonar from maven you can add it manually:

    mvn sonar:sonar -Dsonar.clover.reportPath=\target\site\clover\clover.xml