Skip to content

Keep dependencies that constrain resolution in RemoveRedundantDependencies - #195

Merged
timtebeek merged 2 commits into
mainfrom
tim/redundant-version-constraints
Aug 17, 2026
Merged

Keep dependencies that constrain resolution in RemoveRedundantDependencies#195
timtebeek merged 2 commits into
mainfrom
tim/redundant-version-constraints

Conversation

@timtebeek

Copy link
Copy Markdown
Member

A Gradle declaration like implementation('org.yaml:snakeyaml') { version { prefer '2.0'; strictly '[2.0,2.1)' } } carries no version in its coordinate and exists to pin resolution, typically above what an imported BOM manages, but isRedundant compared only groupId, artifactId, resolved version and declared exclusions — so it saw the artifact supplied transitively at the very version the constraint had forced, and deleted the whole block.

Observed on Netflix/conductor, where the Spring Boot 2.7.3 BOM manages snakeyaml 1.30 and jackson-bom 2.13.3 and these blocks are what lift them to 2.0 and 2.15.x; the removal was also partial, dropping the jackson-core and jackson-annotations pins while keeping the jackson-databind one, which cannot resolve to a working Jackson classpath.

This skips any candidate whose requested version is a range or dynamic version. The strict range surfaces in getRequested().getVersion(), so matching on version syntax rather than on requested-differs-from-resolved keeps versionless BOM-managed declarations removable and does not trip over Maven ${...} placeholders; Maven ranges use the same syntax, so both ecosystems are covered by the one guard in isRedundant.

The added regression test reproduces the reported shape and fails without the guard.

…encies`

A Gradle declaration such as

    implementation('org.yaml:snakeyaml') {
        version {
            prefer '2.0'
            strictly '[2.0,2.1)'
        }
    }

carries no version in its coordinate and exists to pin resolution, typically
above what an imported BOM manages. `isRedundant` compared only groupId,
artifactId, resolved version and declared exclusions, so it saw the artifact
supplied transitively at the very version the constraint had forced and deleted
the whole block, handing the version back to the rest of the graph.

Observed on Netflix/conductor, where the Spring Boot 2.7.3 BOM manages snakeyaml
1.30 and jackson-bom 2.13.3 and these blocks are what lift them to 2.0 and
2.15.x. Removal was also partial, dropping the jackson-core and
jackson-annotations pins while keeping the jackson-databind one, which cannot
resolve to a working Jackson classpath.

Skip any candidate whose requested version is a range or dynamic version. The
strict range surfaces in `getRequested().getVersion()`, so matching on version
syntax rather than on requested-differs-from-resolved keeps versionless
BOM-managed declarations removable and does not trip over Maven `${...}`
placeholders. Maven ranges use the same syntax, so both ecosystems are covered.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Aug 17, 2026
@timtebeek
timtebeek merged commit c4df608 into main Aug 17, 2026
1 check passed
@timtebeek
timtebeek deleted the tim/redundant-version-constraints branch August 17, 2026 18:39
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant