I’m having trouble getting pull request code coverage analysis to work on particular Maven project. The long-lived branch will display test coverage analysis, but the pull requests will not.
From within the module directory, I generate the exec files: mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent test -DskipTests=false -Dgroups=small
And confirmed that the files are generated.
I then run the sonar analysis step: mvn sonar:sonar -Dsonar.projectKey=<project-key> -Dsonar.verbose=true -Dsonar.host.url=https://sonarcloud.io -Dsonar.pullrequest.branch=alwyn-test-pr-2 -Dsonar.pullrequest.base=release-alwyn -Dsonar.pullrequest.key=1602 -Dsonar.login=<key>
However, I’ve tried the same steps against a test repository and am able to get PR test coverage to display.
The only difference I’ve been able to find between the working and non-working repos is that the non-working repo outputs: [WARNING] File '/Development/app/java/common/src/main/java/com/blah/util/FakeUtil.java' was detected as changed but without having changed lines
The above warning seems incorrect given that this a new file that I’ve added in the PR.
Recently we found this bug: https://jira.sonarsource.com/browse/SONARSCGIT-35
Essentially the detection of new lines might not work if the root directory of the project doesn’t match the root of the git repository.
Is it the case in your project?
Thanks for highlighting that issue; it looks like that was the cause!
I copied our code into a new repository with the code to analyse in the root folder. Ran a base analysis on “master” and then on a “test” branch targeting “master”; the SonarCloud results then showed both changed lines and missing test coverage: