Skip to content

Fix empty dependencies block left after constraint-to-rule conversion#6754

Merged
timtebeek merged 3 commits intomainfrom
fix-apply-from-transitive-overrides
Feb 18, 2026
Merged

Fix empty dependencies block left after constraint-to-rule conversion#6754
timtebeek merged 3 commits intomainfrom
fix-apply-from-transitive-overrides

Conversation

@Jenson3210
Copy link
Copy Markdown
Contributor

@Jenson3210 Jenson3210 commented Feb 17, 2026

Summary

  • Fix DependencyConstraintToRule.isEmptyDependenciesBlock to handle truly empty dependencies {} blocks (0 statements)
  • When UpgradeTransitiveDependencyVersion adds constraints to build.gradle and the Spring DM plugin converts them to resolutionStrategy, the leftover empty dependencies {} block was not being cleaned up
  • Add test coverage for the apply from: pattern with transitive dependency constraints

Changes

  • DependencyConstraintToRule: Add check for b.getStatements().isEmpty() in isEmptyDependenciesBlock — previously only checked for single null-return statements
  • UpgradeTransitiveDependencyVersionTest: Add addConstraintWithApplyFrom() and useResolutionStrategyWithApplyFromWhenSpringDependencyManagementPluginIsPresent() tests

Test plan

  • useResolutionStrategyWithApplyFromWhenSpringDependencyManagementPluginIsPresent fails without the fix, passes with it
  • All existing UpgradeTransitiveDependencyVersionTest tests pass
  • All existing DependencyConstraintToRuleTest tests pass

@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite Feb 17, 2026
Copy link
Copy Markdown
Member

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Hmm; all tests seen to pass even if I revert the change!

@github-project-automation github-project-automation Bot moved this from Ready to Review to In Progress in OpenRewrite Feb 17, 2026
@timtebeek
Copy link
Copy Markdown
Member

There's a very similar effort in #6650 that I'd love your eye on as well @Jenson3210

@Jenson3210
Copy link
Copy Markdown
Contributor Author

We might need this change in multiple recipes 🤔

Will have a look at the other one tomorrow.

@Jenson3210 Jenson3210 changed the title Fix transitive dependency overrides duplicated in apply from: scripts Fix empty dependencies block left after constraint-to-rule conversion Feb 18, 2026
When dependencies are declared in a separate file loaded via
`apply from: 'dependencies.gradle'` and the Spring dependency
management plugin is active, UpgradeTransitiveDependencyVersion
incorrectly:
1. Adds configurations.all/resolutionStrategy to both build.gradle
   AND dependencies.gradle (should only be in build.gradle)
2. Adds an empty dependencies {} block to build.gradle
3. Creates syntax errors in dependencies.gradle
When a Gradle project uses `apply from: 'dependencies.gradle'` to
define dependencies in a separate file, UpgradeTransitiveDependencyVersion
was adding constraints (and resolutionStrategy rules for Spring DM) to
BOTH build.gradle and the applied script. This caused:
- Duplicate configurations.all blocks
- Syntax errors in the applied script
- Empty dependencies {} blocks left behind

Only add constraints to primary build files (build.gradle/build.gradle.kts),
not to applied scripts. Also fix DependencyConstraintToRule to properly
remove empty dependencies blocks with 0 statements.
…dencyVersion

Applied scripts like dependencies.gradle already don't get constraints
added due to the DEPENDENCIES_DSL_MATCHER not matching non-type-attributed
method invocations in applied scripts. The isPrimaryBuildFile guard was
redundant.

The actual fix is the DependencyConstraintToRule isEmptyDependenciesBlock
change (from the previous commit) which properly cleans up empty
dependencies {} blocks after constraints are converted to resolutionStrategy.
@Jenson3210 Jenson3210 force-pushed the fix-apply-from-transitive-overrides branch from ec64ae3 to ac63f87 Compare February 18, 2026 09:52
@timtebeek timtebeek merged commit 2ae43a8 into main Feb 18, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Feb 18, 2026
@timtebeek timtebeek deleted the fix-apply-from-transitive-overrides branch February 18, 2026 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gradle recipe Requested Recipe

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants