Chapter 12Lesson 03~110 minutes

New Code, Clean-as-You-Code, Baselines, and Legacy Modernization: Configuration, Design Patterns, and Trade-Offs

Choose among Previous version, Number of days, Specific analysis, and Reference branch while balancing release cadence, SCM semantics, legacy backlog governance, auditability, and edition boundaries.

Previous versionNumber of daysReference branchGovernanceTrade-offs

Learning objectives

  • Select an appropriate new-code definition for versioned releases, continuous delivery, controlled cycles, and branch comparisons.
  • Distinguish global baseline inheritance from project-specific overrides and commercial branch-level controls.
  • Use Clean-as-You-Code alongside a separately governed legacy-risk backlog rather than as a big-bang replacement.
  • Explain how projectVersion and SCM history become policy inputs, not cosmetic metadata.
  • Assess portability, auditability, developer experience, CI reliability, edition boundaries, and rollback for each option.
  • Design an explicit baseline-change control record with owner, reason, evidence, impact, and expiry/review.

1. The definition is an operating-model choice

No single New Code definition is universally correct. A release train, a trunk-based SaaS service, a regulated modernization program, and a feature-branch workflow have different reference points. The goal is not to choose the option that produces the fewest failures; it is to choose the option whose boundary matches the organization’s delivery semantics and can be explained later.

2. Decision table: match the baseline to the delivery model

Pattern Typical definition Evidence needed Rollback / failure risk
Versioned product releases Previous version Release/version source, first analysis of current version, Git revision Accidental/result-driven version bump moves the baseline
Frequent continuous delivery Number of days Window length, analysis date/time, commit dates, SCM state Population drifts automatically; old unresolved issues age into overall code
Explicit modernization or cycle checkpoint Specific analysis Approved analysis key, revision, analysis date/buildString, change record Manual reset can launder a failure if moved without governance
Branch/PR comparison Reference branch Reference branch, target/common ancestor, full history, edition capability Wrong/stale reference or shallow history changes comparison semantics

3. Previous version: make release identity deliberate

Previous version works well when a version means something operational: a release, supported train, or milestone. Scanner CLI users should set sonar.projectVersion from an authoritative version source. Do not generate a new unique version for every CI build; that turns the baseline into a moving target.

Maven and Gradle can supply versions from build metadata. Whatever the source, retain the exact value in the analysis manifest. Changing the version is a release-governance event because it changes the start of the new-code period.

4. Number of days: predictable cadence, moving evidence

A time window is useful for continuous delivery when no release version provides a stable cycle boundary. The trade-off is that the population changes with the clock. Current Community Build documentation allows a maximum of 90 days and uses 30 days as the default example; 7 or 14 days are also common.

For audits and regression comparisons, always timestamp the observation. “New coverage was 92%” is incomplete if the 14-day window later becomes a different set of lines.

5. Specific analysis: precise but governance-heavy

Specific analysis is ideal for a controlled migration checkpoint because the reference can be tied to a concrete revision and analysis key. Its weakness is precisely that humans can move it. Current Community Build intentionally keeps this option out of the normal UI and directs administrators to the Web API, reducing the temptation to update it casually after every run.

Minimum baseline record
project key + definition type + analysis key + analysis date + revision + buildString + approver + reason + review/expiry + rollback target

6. Reference branch: comparison semantics and edition boundaries

Reference branch compares current code against another branch using SCM evidence. It is conceptually different from a time period. Full Git history and the correct reference matter because the scanner needs enough history to identify changed lines reliably.

Current Community Build’s feature matrix must be checked carefully: Community Build is intentionally narrower than commercial SonarQube Server for branch analysis, while pull-request capabilities have their own restrictions. Do not teach a Server-only branch topology as a mandatory Community Build lab. When the feature is unavailable, model it with a two-branch local Git diff and document the intended SonarQube setting as a simulation.

7. Clean-as-You-Code versus big-bang remediation

Clean-as-You-Code

Strictly govern new/changed code. Repair nearby old code opportunistically. Track legacy risk separately. Preserves delivery while making the trend improve.

Big-bang cleanup

Attempts to make all inherited code satisfy a new standard immediately. Appropriate only when risk/regulation/business context justifies the cost and delivery disruption.

Ignore legacy

Not a modernization strategy. Severe security/reliability or compliance risks still require ownership, deadlines, compensating controls, or explicit acceptance.

A mature program often uses a new-code gate as the default release control plus a legacy-risk backlog with severity-based SLAs, remediation campaigns, and trend metrics. That separates “do not add debt” from “reduce inherited debt” without confusing either objective.

8. Global baseline versus project-specific policy

Community Build’s global New Code baseline applies by default. A project-specific definition overrides it. That means a global administrator can improve consistency, while project administrators still need a documented reason for exceptions.

Policy level Use Evidence Risk
Global baseline Organization default Definition + value + effective date A global change can affect many inheriting projects at once
Project override Project-specific delivery model Override type/value + owner + exception rationale Uncontrolled diversity makes cross-project metrics incomparable
Branch-level (where supported) Branch-specific workflow Branch/reference + edition + SCM evidence More policy states to govern and troubleshoot

9. Baseline-change control template

New Code policy change record
Project:
Current definition / value:
Proposed definition / value:
Current project revision and last analysis key:
Reason tied to delivery model (not gate result):
Expected effect on new-code population:
Legacy-risk impact:
Affected quality-gate conditions:
SCM / branch / version prerequisites:
Edition prerequisites:
Approver / owner:
Verification plan:
Rollback definition / value:
Review or expiry date:

If the record cannot explain why the policy matches the delivery model independent of today’s pass/fail result, the change is not ready.

10. Worked selection scenario

Scenario: a 12-year service deploys several times per day, has no release-version boundary, and carries a known low-coverage legacy layer. The team wants new work to meet high coverage while keeping the legacy backlog visible.

Choice: a governed Number-of-days baseline can match the delivery cadence better than Previous version. Pair it with the Sonar way new-code gate and a separate legacy backlog. Record the window length, full SCM checkout, gate conditions, and owner. Reject the proposal to set the window to one day only after a failing analysis unless that one-day cadence was already the approved policy.

Knowledge check

Which definition is normally best aligned with regular formal releases?

Why can two projects with 90% new coverage still be poor comparison peers?

When is Specific analysis attractive?

Does Clean-as-You-Code remove the need for legacy-risk management?

What is the first question before using Reference branch?

Next lesson

Diagnose baseline laundering and misleading modernization signals

Lesson 4 turns common New Code mistakes into causal failure cases and shows how to preserve the original red evidence before correcting policy.

Official references and version notes

Version and compatibility note

Rechecked 2026-09-07. Mandatory executable examples target SonarQube Community Build 26.9.0.129388 and SonarScanner CLI 8.1.0.6389. Current Community Build documentation lists Previous version, Number of days, Specific analysis, and Reference branch as New Code definition modes; the project-level definition overrides the global baseline, whose default is Previous version. Specific analysis is configured through the Web API. Commercial branch analysis and broader enterprise capabilities are not required by this chapter. Re-check the linked primary documentation and your instance’s built-in Web API before automating against another release.

Keep the academy open

Support free, practical DevOps education.

Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.

Ethereum / ERC-20
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0Send only Ethereum/ERC-20 compatible assets to this address.