Commit 2ae43a8
authored
Fix empty dependencies block left after constraint-to-rule conversion (#6754)
* Add failing test for apply from: with Spring DM plugin
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
* Fix transitive dependency overrides duplicated in apply from: scripts
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.
* Remove redundant isPrimaryBuildFile check from UpgradeTransitiveDependencyVersion
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.1 parent 878b52a commit 2ae43a8
2 files changed
Lines changed: 81 additions & 0 deletions
File tree
- rewrite-gradle/src
- main/java/org/openrewrite/gradle
- test/java/org/openrewrite/gradle
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
460 | 460 | | |
461 | 461 | | |
462 | 462 | | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
463 | 466 | | |
464 | 467 | | |
465 | 468 | | |
| |||
Lines changed: 78 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
84 | 122 | | |
85 | 123 | | |
86 | 124 | | |
| |||
995 | 1033 | | |
996 | 1034 | | |
997 | 1035 | | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
998 | 1076 | | |
999 | 1077 | | |
1000 | 1078 | | |
| |||
0 commit comments