Can the XPath rule template still work for the java?

I can see the xpath rule template for jave in my sonarqube(version 9.5) with the tag “DEPRECATED”

I can add a rule from this rule template , such as the xpath expression="//VariableDeclaratorId".

And this rule is actived in my qulity profios.I use mvn sonar:sonar to scan my java source. But it seems to get no issues.

Does it still work ? Or it is really DEPRECATED?


Are you sure you’ve added your XPath rule to the profile in use? Creating the rule isn’t enough; you need to activate it in the profile being used to analyze your project.

If you’re using the Sonar way profile, you’ll need to create a new profile, since that profile isn’t modifiable. The docs should help.


Thanks for your reply!

I do add the rule in my quality profile : “ide_rules”

and I can see this message in my scanning logs

I can see my test file “” is indexed in the code page in sonarqube wtihout any issues.

En,I tried to create an xpath rule for xml, xpath expression="/project/properties[sonarqube.version=]", add the rule to profile “custom-xml-rules”. The rule works and reports issues.

Can you show me a valid example for java xpath rule configuration?


This is probably a question of correctly structuring the XPath to address the AST created by Java analysis. We used to publish a checker, but I guess that went away when we deprecated the rule. So… I’m not sure what help anyone can be. Your best bet is probably to switch to writing this in Java via a custom plugin.

I know that’s not what you want to hear, but it’s the best I’ve got.