I am using SonarQube * Community Edition* Version 8.9.7 (build 52159) with Scanner with Maven. I have question regarding the new code baseline (leak period) and the way SonarQube manages it.
When you set the new code baseline you have several options (last version, number of days, past analysis) but at the end, does this represents a date and no changes in the code, isn’t it? So the new code are all the lines that have been added or changed since this data, isn’t it?
Yes, the New Code Period is ultimately transformed into a date, and all code introduced/changed in analyses after that date is considered “new”. This is slightly different than say, an SCM date (you cannot perform a first analysis, set the New Code Period to 30 days, and expect code introduced in the last 30 days to immediately be considered New Code. It’s all based on the analysis itself).
Thanks you for the answer. Let me check if I understood it correctly with an example. I am talking about Developer Edition now, with PR analysis. Question in bold.
Create a project an make a first analysis of the main branch
Set the new code baseline as ‘reference branch’ with main. And the new code baseline for the main branch for ‘past version’
Developer A creates a branch from main and start working on it eventually creates a PR. In this PR analysis the new code is the lines added from the last analysis of the main branch, isn’t it?
Developer B creates a branch from main and start working on it eventually creates a PR and analyses it.
Developer A merges is branch into main
The next analysis of the PR of developer B will change? So the changes done before the merge of developer A are not counted as new code and the ones done after the merge are countes as new code?
Pull Request Analysis works a bit differently – because SonarQube is able to use SCM information to determine exactly what the changed lines are (and only consider those lines as new code, and only raise issues on those lines). Essentially the diff is the New Code Period for PR analysis.
There should not be code from the target branch polluting the New Code of a PR analysis.