Skip to content

Add NoSystemScopeDependencies cleanup recipe#7055

Merged
jkschneider merged 7 commits intomainfrom
tim/remove-system-scope-deps
Mar 22, 2026
Merged

Add NoSystemScopeDependencies cleanup recipe#7055
jkschneider merged 7 commits intomainfrom
tim/remove-system-scope-deps

Conversation

@timtebeek
Copy link
Copy Markdown
Member

Summary

Adds a new cleanup recipe NoSystemScopeDependencies that fixes Sonar rule S3422 by removing system-scoped Maven dependencies when they are available in configured repositories.

System scope is problematic because it requires a machine-specific <systemPath>, is non-portable, and cannot be packaged in artifacts. The recipe verifies artifact availability before removing the scope, leaving truly local-only dependencies unchanged.

Changes

  • New recipe class: NoSystemScopeDependencies.java
  • Recipe only removes <scope>system</scope> and <systemPath> if the dependency version exists in configured repositories
  • Works for both <dependencies> and <dependencyManagement> sections
  • Comprehensive test suite with 6 test cases covering all scenarios

Test Plan

  • All 6 tests in NoSystemScopeDependenciesTest pass
  • Tests cover: artifact available in repo, no systemPath element, dependencyManagement section, artifact not in any repo, non-system scopes, and dependencies without scope

…pendencies

This recipe removes <scope>system</scope> and <systemPath> from Maven
dependencies when the artifact is available in configured repositories.
System scope is deprecated, non-portable, and problematic because it
requires a machine-specific systemPath and is not packaged in artifacts.

The recipe only removes system scope if the dependency can be verified
to exist in a configured Maven repository by checking available versions.
Dependencies not found in any repository are left unchanged.

Fixes Sonar finding: 'Dependencies should not have "system" scope'
Include the new recipe in the BestPractices composite recipe and
add its entry to recipes.csv.
@timtebeek timtebeek added recipe Requested Recipe maven labels Mar 19, 2026
Comment on lines +34 to +35
final String description = "Replaces `<scope>system</scope>` with the default compile scope and removes " +
"`<systemPath>` for dependencies that are available in configured repositories.";
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we know this isn't a complete solution for all cases, but it allows folks to push that jar somewhere and then from there see the system scope dropped here.

@timtebeek timtebeek moved this from In Progress to Ready to Review in OpenRewrite Mar 21, 2026
@jkschneider jkschneider merged commit 03048dc into main Mar 22, 2026
1 check passed
@jkschneider jkschneider deleted the tim/remove-system-scope-deps branch March 22, 2026 17:00
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maven recipe Requested Recipe

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants