Fix empty dependencies block left after constraint-to-rule conversion#6754
Merged
Fix empty dependencies block left after constraint-to-rule conversion#6754
Conversation
timtebeek
approved these changes
Feb 17, 2026
timtebeek
requested changes
Feb 17, 2026
Member
timtebeek
left a comment
There was a problem hiding this comment.
Hmm; all tests seen to pass even if I revert the change!
Member
|
There's a very similar effort in #6650 that I'd love your eye on as well @Jenson3210 |
Contributor
Author
|
We might need this change in multiple recipes 🤔 Will have a look at the other one tomorrow. |
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.
ec64ae3 to
ac63f87
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DependencyConstraintToRule.isEmptyDependenciesBlockto handle truly emptydependencies {}blocks (0 statements)UpgradeTransitiveDependencyVersionadds constraints tobuild.gradleand the Spring DM plugin converts them toresolutionStrategy, the leftover emptydependencies {}block was not being cleaned upapply from:pattern with transitive dependency constraintsChanges
DependencyConstraintToRule: Add check forb.getStatements().isEmpty()inisEmptyDependenciesBlock— previously only checked for single null-return statementsUpgradeTransitiveDependencyVersionTest: AddaddConstraintWithApplyFrom()anduseResolutionStrategyWithApplyFromWhenSpringDependencyManagementPluginIsPresent()testsTest plan
useResolutionStrategyWithApplyFromWhenSpringDependencyManagementPluginIsPresentfails without the fix, passes with itUpgradeTransitiveDependencyVersionTesttests passDependencyConstraintToRuleTesttests pass