New Code Analysis Scope for unusual branching

We are using SonarQube Server Developer Edition (2025.1.4 LTA) and trying to analyse “New Code” of one of our projects.

Our branching/versioning is a bit unusual in this project:

  • We use Maven and set the revision during build to “branchName-SNAPSHOT” (e.g., “master-SNAPSHOT”, “2025.2-SNAPSHOT”). This is also the version shown in SonarQube.

  • Historically, the pom version didn’t match the branch (e.g., branch “2025.0” had version “13.7.0-SNAPSHOT”). We’ve since aligned versions with branch names.

In SonarQube, we first set “New Code” to “Previous Version,” but that didn’t work well because versions like “master-SNAPSHOT” were mixed among other (in)consistent versions.

We then considered “Reference Branch.” The challenge: our release branches change regularly.

Current setup:

  • master → Reference branch: 2025.2

  • 2025.2 → Reference branch: 2025.1

When we cut the next release (2026.0 from master), we’ll need to remember to update master’s reference branch accordingly.

We are looking for a way to automatically being able to set to the correct reference branches for our analysis scopes without manual interference. Currently we have not found any way to do it automatically.

Do you have any idea for improving our SonarQube configuration for New Code in this setup?

Hi,

There’s no built-in way to handle this nicely. I suggest you explore including this in a release-time script via the API.

The best way to master the API is to perform the desired action via the UI and eavesdrop to see which calls the UI made to accomplish the action.

You may also find this guide helpful.

 
HTH,
Ann