which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
SonarQube version 8.5.1
what are you trying to achieve
I have several custom checkstyle checks that extends from com.puppycrawl.tools.checkstyle.api.AbstractCheck, I want to upload the violations that belongs to my custom checkstyle checks to SonarQube server.
what have you tried so far to achieve this
I have several custom checkstyle checks that extends from com.puppycrawl.tools.checkstyle.api.AbstractCheck, I ran the mvn checkstyle:checkstyle command
and get the checkstyle report (checkstyle-result.xml) which contains a lot of violations, some of them belongs to my custom checkstyle checks. I upload the test result by command mvn sonar:sonar -Dsonar.java.checkstyle.reportPaths=target/checkstyle-result.xml …. On the SonarQube website, I can see violations that belong to checkstyle built-in checks, but I can’t see violations that belong to my custom checkstyle checks. For example, I got a violation in checkstyle-result.xml, but even I upload the test result, I can’t see this violation on SonarQube server.
From the code of the importer, I can say that the source attribute should start with com.puppycrawl.tools.checkstyle.checks. and that the message attribute should not be empty. If it is not the case, the issue will not be imported and you should see a line in the debug logs of the analysis.
It it possible to make this happen on your side? If not, could you share the report you are talking about? Or a sample, containing both a violation correctly imported and one not.
Example of a rule + its violation not being imported to SonarCloud (most likely due to the same reason - the source attribute doesn’t start with com.puppycrawl.tools.checkstyle.checks. - as this message is being logged at DEBUG level).
<module name="MatchXpath">
<property name="id" value="singleLineCommentStartWithSpace"/>
<property name="query"
value="//SINGLE_LINE_COMMENT[./COMMENT_CONTENT[not(starts-with(@text, ' '))
and not(@text = '\n') and not(ends-with(@text, '//\n'))
and not(@text = '\r') and not(ends-with(@text, '//\r'))
and not(@text = '\r\n') and not(ends-with(@text, '//\r\n'))]]"/>
<message key="matchxpath.match" value="Single line comment text should start with space."/>
</module>
Violation not being imported:
<error line="11" column="1" severity="warning" message="Single line comment text should start with space." source="singleLineCommentStartWithSpace"/>
NOTE: it’s just 1 example, we can provide much more other rules violations. that are not being imported to SonarCloud.
Environment details:
SonarCloud
Sonar Analyzing and importing of external reports is done via: Jenkins + Maven (sonar-maven-plugin) + JDK11
Checkstyle version: 9.3 (the Checkstyle report is being collected with JDK1.8).
Is there any workaround we can apply at our side to fix this?
@Quentin a workaround I found is to prepend the id with the prefix starting from com.puppycrawl.tools.checkstyle.checks. - then the violation is getting picked up by SonarCloud importer.
However the question is: does the importer truly need filtering by the id at all? Many violations may not have the id prefix expected by the importer.