Debugging custom rules at runtime

Hello,

I was wondering if there is a good way to run custom sonar rules on exising projects in workspace (No just the test files), for an easy debug ?
Am I missing something ?

Hello Kad,

Yep, it’s possible. The easiest way (from my point of view) would be to use a sample maven project.
In order to to so, you need:

  • a local instance of SonarQube, with your custom plugin installed;
  • the custom rule(s) you want to test enabled
  • some break points in your custom rule(s)
  • running an analysis with mvnDebug
> mvnDebug clean install sonar:sonar
Preparing to execute Maven in debug mode
Listening for transport dt_socket at address: 8000
...
  • Start listening in your IDE debug mode as a remote java application

Example with eclipse:

Hope this helps,
Michael

3 Likes

Thanks Michael, this will save me a lot of time :smiley: