Using SonarQube (version 3.0) I am trying to implement a blacklist of java libraries. For example I'd like for SonarQube to generate a code smell for any java file that contains an import for org.apache.lang.StringUtils
I did find this rule: "Track uses of disallowed dependencies" however as previously stated I want to focus on the java file import statements themselves. e.g.
import org.apache.lang.StringUtils; // SonarQube should generate smell for this line
import java.awt.Component;
Ideally I'd like to maintain a centralized list of deprecated/bug causing imports that would cover the following use cases:
Following David M. Karr's advice I looked through the custom rules documentation and found this template; Track uses of disallowed classes
Opening this template for configuration, there appears a note explaining that the rule parameters (in this case the class name) allows for regex - and explicitly advises to use regex when targeting packages.
The custom rule with org.apache.commons.lang.StringUtils
passed to the ClassName parameter achieved the desired results stated in the question. Additionally the entire package can be targeted with org.apache.commons.lang.*
In SonarQube Dashboard
org.apache.commons.lang.StringUtils
or use regex to target an entire package e.g. org.apache.commons.lang.*