mavensonar-maven-plugin

${session.executionRootDirectory} is not recognized by sonar-maven-plugin


I have several levels of nested Maven projects, where every module can participate in the global integration tests. To have a global, multi module coverage, I've configured jacoco to use and share the same file accross modules, using the Maven variable ${session.executionRootDirectory}:

<execution>
    <id>pre-integration-test</id>
    <phase>pre-integration-test</phase>
    <goals>
        <goal>prepare-agent-integration</goal>
    </goals>
    <configuration>
        <propertyName>jacoco.failsafeArgLine</propertyName>
        <destFile>${session.executionRootDirectory}/target/jacoco-it.exec</destFile>
    </configuration>
</execution>

This way, the same data file is used by each module, no matter how deep it is nested in the submodules. I've checked, a correct data file is generated by jacoco when launching "mvn clean install".

Now the problem appears when launching mvn sonar:sonar. It seems that the plugin can not replace that variable with the real path. I can see the following in the logs

[INFO] JaCoCoItSensor: JaCoCo IT report not found: /home/tomcat/.jenkins/jobs/MYJOB/workspace/${session.executionRootDirectory}/target/jacoco-it.exec

It doesn't work better when using @{session.executionRootDirectory}.

Any workaround?


Solution

  • Following a comment in this bug report at SonarSource, advising to use the following configuration:

    <plugin>
        <groupId>com.github.goldin</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <version>0.2.5</version>
        <executions>
            <execution>
                <id>set-sonar.jacoco.reportPath</id>
                <goals>
                    <goal>set-properties</goal>
                </goals>
                <phase>initialize</phase>
                <configuration>
                    <rawProperties>
                        sonar.jacoco.itReportPath = ${session.executionRootDirectory}/target/jacoco-it.exec
                    </rawProperties>
                    <addDollar>true</addDollar>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    ... which was unfortunately not compatible with Maven 3.1+, I've used and built from sources that fork, and then I was able to make everything work correctly with Maven 3.2.3.