3
votes

I'm having some problems to make Sonar display code coverage for tests written in both Java and Groovy. I have a Maven multi-module project where a module can be exemplified like this:

firstServer
  src/test/groovy
    package1
      GroovyTest1.groovy
      GroovyTest2.groovy
  src/test/java
    package2
      JavaTest1.java
      JavaTest2.java

The pom.xml for firstServer looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
...
<build>
    <plugins>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.7.201606060606</version>
            <configuration>
                <destFile>${sonar.jacoco.reportPath}</destFile>
                <append>true</append>
            </configuration>
            <executions>
                <execution>
                    <id>agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        ...
    </plugins>
</build>

My Sonar properties are in the parent pom.xml:

<properties>
    <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
    <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
    <sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
</properties>

When I run the command mvn package sonar:sonar and visit SonarQube to see the results, the code coverage only takes java classes into account. I can't see any groovy classes among my unit tests even though I have many of them. I guess that I'm missing something in my POM files but I don't know what. I have read that it is possible to have a mix of Groovy and Java test classes when using Sonar and JaCoCo. My question is simply, what am I missing?

Thanks in advance!

2

2 Answers

0
votes

You need to also add the sources and tests configuration:

<sonar.sources>src/main/java,src/main/groovy</sonar.sources>
<sonar.tests>src/test/java,src/test/groovy</sonar.tests>

It seems that the plugin ignores Groovy otherwise.

0
votes
  1. Install the Groovy plugin in Sonar. Login as admin/admin and go to the administration/system/update-center tab
  2. Add the following property in the pom file <sonar.tests>src/test/groovy,src/test/java</sonar.tests>