How to analyse only new added lines of code?

We recently integrated sonarqube to our existing build and release environment. Everytime any commit triggers sonar scanning total project again instead of latest commit.

How to make sonar to scan only the latest commits from second time onwards as it is taking lot of time for scanning.

If not let us know any alternative for the same.

Hi @Jigar_Mehta1

SonarQube cannot analyze only changes at the moment. We have many “advanced” rules that can raise new issues on code that has not been touched. For example if you change a method behavior to return null in some cases while previously it was always non null, all places calling this method should be checked again for possible NPE.
In the past we gave multiple attempts at implementing “incremental”/“partial” analysis, but the risk of missing important issues was too high. Also, using caching of some intermediate analysis state was tried, but like often with caching, it is not a silver bullet. Performances are sometimes worst than doing a clean analysis from scratch.

What I would recommend to you is to report factually your issue, and let us investigate what are the options, before jumping to the conclusion that SonarQube should do diff analysis:

  • what do you call “taking a lot of time for scanning”? Please give numbers.
  • what is the size of you project? Number of files, number of ncloc?
  • do you have only SonarSource rules, or do you also have custom rules, or third party plugins like PMD/checkstyle/findbugs?
  • what is the part of the SonarQube analysis compared to the rest of your build/release pipeline (unit tests, integration tests)?

Hi Julien,

Thanks for your revert. Sometimes it takes 5-6 minutes for the entire project to scan, its a Nodejs code.

Secondly i have been researching and got to know that SonarLint IDE can help to incremental changes issue.? Is that something you are aware of?

This is hard to tell if this is an issue or expected, because it heavily depends on the size of your project. Is it TypeScript or JavaScript code? How many lines of code?

SonarLint will indeed help to decrease the feedback loop, since you will see issues reported in your IDE, as you code. The analysis speed is less a concern since files are analyzed only when you work on them. Our recommended workflow is to use SonarLint to catch as many issues as possible while coding, and then use SonarQube or SonarCloud to do a full analysis during CI pipeline (analyzing pull requests before merge is even better).

Hi Julien,

Can you please help me with details on new Code Period.

Hi Julien,

There is something known as new code period, can you help me with a video or a example which is easily understandable.


The first link that you provided should help you understand the concept and how to configure the period on your SonarQube instance. I don’t think we have a video to explain the concept. What are you struggling with ?