sonar project.properties to ignore files containing a regular expression

21.7k Views Asked by At

I am trying to exclude files containing generated code in a sonar project.properties file. I have added the following to project.properties.

sonar.issue.ignore.allfile=.*generated.*,.*GeneratedCodeAttribute.*

I get the following error: ERROR: Caused by: Exclusions > Issues : Invalid format. The field does not define a regular expression: null

I have tried a lot of combinations. None of these work, same error.

sonar.issue.ignore.allfile=file:generated
sonar.issue.ignore.allfile=generated
sonar.issue.ignore.allfile=regex:generated

etc...

Any ideas on how to set this property in a project.properties file?
I am aware that this can be done in the user interface, I need the project file syntax for multiple exclusions. I have read the source code, but cannot figure out what's missing.

3

There are 3 best solutions below

7
On BEST ANSWER

Quoting the Documentation here (Emphasis is mine)

You can have SonarQube ignore issues on certain components and against certain coding rules. Go to Configuration > Settings > Exclusions > Issues. Note that the properties below can only be set through the web interface because they are multi-valued.

0
On

Check the last section in the link given by @Tensibai. Using sonar.exclusions in the project-properties file should work.

# Exclude all classes ending by "Bean"
# Matches org/sonar.api/MyBean.java, org/sonar/util/MyOtherBean.java, org/sonar/util/MyDTO.java, etc.
sonar.exclusions=**/*Bean.java,**/*DTO.java

# Exclude all classes in the "src/main/java/org/sonar" directory
# Matches src/main/java/org/sonar/MyClass.java, src/main/java/org/sonar/MyOtherClass.java
# But does not match src/main/java/org/sonar/util/MyClassUtil.java
sonar.exclusions=src/main/java/org/sonar/*
1
On

You can configure the propertie sonar.issue.ignore.allfile to ignore all issues on file by setting the project.properties file as followed:

sonar.issue.ignore.allfile=r1
sonar.issue.ignore.allfile.r1.fileRegexp=GeneratedFile

As documented:
If this regular expression is found in a file, then the whole file is ignored.
means you'll need to set the regex, GeneratedFile for example, in the files that you want to be ignored.