SonarQube Quick Tip: Exclude Files from Analysis and Speedup Analysis

I setup a new CI build with SonarQube analysis this week and noticed right off there were far more lines of code for the project than I was expecting. 

image

So I reviewed the code tree in SonarQube and noticed several very large third party JavaScript files were being included in the analysis like jQuery, bootstrap, Kendo, etc.  Obviously this isn’t my code so there is little value in analyzing it (if you trust the source) and it skews my code metrics.  Thankfully SonarQube provides a configuration options to control what is analyzed under General Settings | Analysis Scope:

image

There are many options on this page.  In my case I needed to exclude source files.  SonarQube uses a nice wildcard syntax to make exclusion easier:

image

We used the following exclusions to ignore the third party source files:

**/*kendo*/**/*
**/*jquery*

With this change our Lines of Code looked much better:

image

image

Faster Too!

The unexpected but happy byproduct of this change was our build analysis times went from 16 minutes to 6 minutes with this single change.  So now the cost of analysis is effectively free on our CI build where before it caused a 10 minute penalty.

If this post was helpful, you have questions or you want to share your results/experience please leave a comment below.  Thanks!

Happy Analyzing!


2 thoughts on “SonarQube Quick Tip: Exclude Files from Analysis and Speedup Analysis”

  1. Thank you for the awesome tip. I did run into some issues as it didn’t ignore the js files located in **/*Scripts*/**/*. Is it case senstive?

Leave a Reply