Inspect versionless managed dependencies inside Maven profiles - #8469
Draft
martinfrancois wants to merge 1 commit into
Draft
Inspect versionless managed dependencies inside Maven profiles#8469martinfrancois wants to merge 1 commit into
martinfrancois wants to merge 1 commit into
Conversation
…ersionless entries under profiles Pins that a coordinates-only dependencyManagement entry inside profiles/profile is left untouched, because isManagedDependencyTag() only matches the top-level path. Marked known-failing with @disabled; inherited limitation disclosed in PR openrewrite#8445.
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.
Suggested review order: 52 of 52 (Score: 0.5)
Review first: #8468
What's changed?
Adds 1 known-failing test to
ManagedDependencyRequiresVersionTestthat reproduces a coverage gap inDependencyManagementDependencyRequiresVersion: versionlessdependencyManagemententries inside<profiles>are never removed, while identical top-level entries are. No recipe code changes.The test is marked
@Disabledso the suite stays green; removing the annotation shows the failure. I used@Disabledinstead of@ExpectedToFailbecause junit-pioneer is not on the rewrite-maven test classpath. The class had 1 test before and has 2 tests with this change. With the annotation in place the class runs 2 tests with 1 skipped and 0 failures; with it removed, 2 tests run and 1 fails.What's your motivation?
Recipe:
org.openrewrite.maven.cleanup.DependencyManagementDependencyRequiresVersion.The recipe removes managed dependencies that have no version. It only does this at the top level of the pom, not inside profiles. The new test uses one pom that holds both cases, so a single run shows the recipe visiting the file and skipping only the profile part.
Before
Actual after the recipe
Using current main, the top-level
dependencyManagementblock is removed, but the profile block is left exactly as it was, including the versionlessjackson-coreentry.Expected after the recipe
The profile MUST retain its
<id>and remove its versionlessdependencyManagemententry, matching what the recipe already does at the top level.The cause is that the no-argument
MavenVisitor.isManagedDependencyTag()matches only/project/dependencyManagement/dependencies/dependency, so profile-scoped entries are never considered.I found this while preparing #8445, which fixes a related defect in this recipe and discloses this inherited limitation in its description.
Anything in particular you'd like reviewers to focus on?
The judgment call. I think this is an improvement, not a bug: the recipe skips these entries rather than producing wrong output, and the recipe contract does not establish whether profile entries are in scope. One point against that reading:
MavenVisitoralready definesPROFILE_MANAGED_DEPENDENCY_MATCHERand uses it in theisManagedDependencyTag(groupId, artifactId)overload, so the no-argument overload is the odd one out. If you agree this should change, I would gladly prepare the fix. If this behavior is intended, feel free to close this and I know it is settled.Any additional context
Pre-existing tests changed: None.
My open #8445 touches the same recipe; it does not fix this. A prior generic attempt to add profile-scoped dependency matchers to
MavenVisitor, #4310, was closed unmerged. One caveat carried over from the top-level behavior and disclosed in #8445: entries that carry<exclusions>or<scope>are not fully inert, so removing them is not always a pure cleanup. This reproduction was prepared with AI assistance (Claude Code). I reviewed the tests and this description.This draft adds a reproduction test only, so the first box stays unticked on purpose; I will complete it together with the fix if you want one. The formatter was run calibrated per file; I declined reindentation of untouched lines.
Checklist
./gradlew buildlocally, and committed any resulting changes torecipes.csv