SonarQube Scans Guidance When the New Code = Previous Version

Hi Everyone,

I am new to the SonarQube world so requesting some guidance on how the scan typically works. At our end, we have New Code in SonarQube added as “Previous Version” .

  • So if I have an apex class with suppose 100 lines that is available in the master branch, I made some changes in dev org and added 111, 112 and 113 lines and committed the same. Now the scan should only occur for the lines 111, 112 and 113 or the entire apex class?
  • Once the above commit is done and I add a couple of more lines - 114, 115 and 116 so since the previous commit already included 111, 112 and 113, the new scan would occur on only on 114, 115 and 116?

Hey there @mohdthus_cisco! The “previous version” new code detection is not based on commits, but on the sonar.projectVersion. You’re thinking “version” in git terms, but that’s not what it means here. Let me rehash your example case:

  • You have a file with 100 lines and you analyze with the property sonar.projectVersion=1.0. This analysis is now tagged as 1.0.
  • You add lines and re-analyze with sonar.projectVersion=1.1, for example. These lines that have been added in 1.1 that are not in 1.0 are new code.
  • You can keep adding more lines in subsequent analyses (=commits), and they will keep being new code, as long as you don’t change the version.
  • You finally run another anlysis with sonar.projectVersion=2 (again, random example number). The code that was previously new code is not new code anymore. Code in version 2 which was not in the previous ones will be new code instead.

Read more about this: Quality standards and new code | SonarQube Server | Sonar Documentation and Parameters not settable in the UI | SonarQube Server | Sonar Documentation . Note that if you’re using the Scanner for Maven or Gradle, the project version can be taken from Maven or Gradle configuration.