Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude directory from SonarQube analysis

When I open a PR on GitHub, SonarQube Cloud checks the source code and reports any problems. I also have the IntelliJ plugin "SonarQube for IDE" installed. By connecting the IDE plugin to SonarQube Cloud, the same rules are used in my IDE and on GitHub.

I want to exclude all the files in src/main/java/db/schema from SonarQube analysis in both cases (in the IDE and on GitHub).

I've added a .sonarcloud.properties file to my project root with the following property:

sonar.exclusions=src/main/java/db/schema/*

But when I manually trigger the SonarQube analysis in the IDE, violations in these files are reported.

like image 307
Dónal Avatar asked Nov 22 '25 21:11

Dónal


1 Answers

As per the documentation

When running in Connected mode with SonarQube (Server, Cloud) or SonarQube Community Build, SonarQube for IDE will ignore local exclusions and fetch file exclusions from the SonarQube (Server, Cloud) server.

This points that the way to configure exclusions is different whether you are running in Connected mode or not.


Connected mode

When in Connected mode, go to the SonarCloud > Project Settings > General Settings > Analysis Scope then search for the Exclusions section and add this pattern

src/main/java/db/schema/**

Local mode

When not in Connected mode, IntelliJ doesn't read exclusions in .sonarcloud.properties (as per the documentation). Instead, you'll want to create a sonar-project.properties file add inside of it the exclusion

sonar.exclusions=src/main/java/db/schema/**

Note: you can read about other approaches in the answers to this very similar question, as well as this one.

like image 179
Tiago Martins Peres Avatar answered Nov 24 '25 21:11

Tiago Martins Peres



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!