Debugging custom rules at runtime

java

(Kad) #1

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 ?


(Michael Gumowski) #2

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


(Kad) #3

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