Gradle ChangeDependency leaves an unversioned dependency when the new coordinates are unmanaged
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 42/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- java
- Domain
- build-system, tooling
Research direction
Start with ChangeDependencyTest#doNotPinWhenNotVersioned and compare it with Maven's ChangeDependencyGroupIdAndArtifactIdTest#managedToUnmanagedExternalizedDepMgmt. Read the GradleProject model and RemoveBomManagedDirectDependencies, then compare with ResolvedPom#getManagedVersion. Done means the Gradle recipe no longer leaves an unversioned renamed dependency when the new coordinates are unmanaged, while preserving managed dependencies and the documented override behavior.
Written by the indexing model from the issue text.
Description
What version of OpenRewrite are you using?
Latest main (560b40cc63).
What is the smallest, simplest way to reproduce the problem?
The Gradle org.openrewrite.gradle.ChangeDependency leaves a renamed dependency without a version whenever the declaration had no version of its own, even when a newVersion is supplied. This is currently asserted by ChangeDependencyTest#doNotPinWhenNotVersioned:
plugins {
id 'java'
id 'org.springframework.boot' version '2.6.1'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
}
dependencies {
runtimeOnly 'mysql:mysql-connector-java' // -> 'com.mysql:mysql-connector-j'
}
Spring Boot 2.6.1 manages mysql:mysql-connector-java but not com.mysql:mysql-connector-j, so the resulting build script does not resolve. overrideManagedVersion is the documented escape hatch, and its own option description says "No check is done on the NEW dependency to verify if it is managed, it relies on whether the OLD dependency had a managed version."
- The Maven side behaves the other way round: it writes an explicit version when it can tell that the new coordinates are unmanaged (
ChangeDependencyGroupIdAndArtifactIdTest#managedToUnmanagedExternalizedDepMgmt), and after #8462 it declines to rename when it has no version to write.
What did you expect to see?
The Gradle recipe not producing a build script that cannot resolve, ideally matching the Maven decision.
What did you see instead?
An unversioned dependency on coordinates nothing manages.
The obstacle is that the GradleProject model does not record which versions come from dependency management, so "is the new GA managed?" cannot be answered the way ResolvedPom#getManagedVersion answers it for Maven. RemoveBomManagedDirectDependencies works around this by downloading each platform(...) POM and querying it, which covers platforms but not the io.spring.dependency-management plugin.
Are you interested in contributing a fix?
- Not immediately — filing to track the Maven/Gradle asymmetry uncovered while fixing #8462.
- Dominant language
- Java
- Stars
- 3.9k
- Forks
- 599
- Avg merge
- 9h 38m
- Merged PRs (30d)
- 557
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from openrewrite/rewrite
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
openrewrite/rewrite#9835 ·
Maintainers usually reply within 1 day
-
bug gradle
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
openrewrite/rewrite#7576 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
openrewrite/rewrite#9834 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
openrewrite/rewrite#9819 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 55/100
openrewrite/rewrite#9817 ·
Maintainers usually reply within 1 day
All issues in openrewrite/rewrite
Similar issues
-
Four TestConstraintBasedAlgorithm tests pass when nothing is thrownPossibly taken @sharanggupta claimed this today. Open
Difficulty 1/5 1-3 hours Newbie friendliness 85/100
-
bug documentation good first issue help wanted priority low size XS
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
martin-francois/symphony-trello#1351 ·
Maintainers usually reply within 1 day
-
Add test coverage for ConvertUtil.parseDate() with NULL inputPossibly taken @mirajul-mollah7 claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 78/100
eclipse-sw360/sw360#4792 · 1 comment ·
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
aws/aws-emulator#30 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 4 days