Can clover instrument groovy code that is not placed under src/main/groovy?

fdonascimento June 14, 2021

I have a project with groovy scripts under src/main/resources/groovy. I have the resources folder configured in the gmavenplus-plugin:

<plugin>
    <groupId>org.codehaus.gmavenplus</groupId>
    <artifactId>gmavenplus-plugin</artifactId>
    <version>1.12.0</version>
    <executions>
        <execution>
            <goals>                
<goal>addSources</goal>                 <goal>addTestSources</goal>               
<goal>compile</goal>                 <goal>compileTests</goal>             </goals>         </execution>     </executions>     <configuration>         <sources>             <source>                 <directory>${project.basedir}/src/main/resources/groovy</directory>                 <includes>                     <include>**/*.groovy</include>                 </includes>             </source>             <source>                 <directory>${project.basedir}/src/main/groovy</directory>                 <includes>                     <include>**/*.groovy</include>                 </includes>             </source>         </sources>         <testSources>           
<testSource>                 <directory>
${project.basedir}/src/test/groovy</directory>                 <includes>                     <include>**/*.groovy</include>                 </includes>             </testSource>         </testSources>     </configuration> </plugin>


This is my clover configuration:

<plugin>
    <groupId>org.openclover</groupId>
    <artifactId>clover-maven-plugin</artifactId>
    <version>4.4.1</version>
    <configuration>
        <includesTestSourceRoots>false</includesTestSourceRoots>
        <includesAllSourceRoots>true</includesAllSourceRoots>
    </configuration>
    <executions>
        <execution>
            <id>clover-groovy-instrumentation</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>setup</goal>
            </goals>
        </execution>
        <execution>
            <id>clover-report</id>
            <phase>verify</phase>
            <goals>
                <goal>clover</goal>
            </goals>
        </execution>
    </executions>
</plugin>


I ran some tests and I have the following results:

1 - Clover can instrument all the java code with no problem. I even placed a class under the resources folder and it worked.
2 - Clover instruments groovy classes and groovy scripts only if they are under the src/main/groovy.
3 - I can see the groovy code in the HTML report, however, they were not included in the XML report. I need that for sonar.
4 - All the java classes and the groovy files under the resources folder are included in the folder target/clover/src-instrumented.
5 - I can see that the java code was instrumented, but the groovy files were not changed.
6 - The groovy files under the src/main/groovy were not added to the src-instrumented folder, but I can see them in the report.
7 - In the maven logs, I can see that clover changed the root sources to ../src-instrumented and src/main/groovy.

[DEBUG] Clover main source directories before change:
[DEBUG] [Clover]  source root [${project.basedir}/src/main/java]
[DEBUG] [Clover]  source root [${project.basedir}/src/main/resources/groovy]
[DEBUG] [Clover]  source root [${project.basedir}/src/main/groovy]
[DEBUG] Clover main source directories after change:
[DEBUG] [Clover]  source root [${project.basedir}/target/clover/src-instrumented]
[DEBUG] [Clover]  source root [${project.basedir}/src/main/groovy]

8 - I also added a groovy file under src/main/java just for testing, but it didn't work either.

It seems that Clover doesn't try to instrument groovy files added to the src-instrumented folder. However, these files were just copied and when Clover read these files later to generate the report, there aren't any instrumentation.


Is there any way to make this work?

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events