Add onlyDirect option to ModuleHasDependency - #199
Open
steve-aom-elliott wants to merge 2 commits into
Open
steve-aom-elliott wants to merge 2 commits into
steve-aom-elliott wants to merge 2 commits into
Conversation
When enabled, transitive dependencies are skipped and only directly declared dependencies are considered when deciding whether a module matches. Mirrors the existing `onlyDirect` option on the Maven and `FindDependency`-style recipes. The Gradle branch factors the depth-0 gate into a small `findMatching` helper so the loop body stays flat.
steve-aom-elliott
marked this pull request as ready for review
September 24, 2026 19:32
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
Adds an
onlyDirectoption toorg.openrewrite.java.dependencies.search.ModuleHasDependency. When enabled, transitive dependencies are skipped and only directly declared dependencies count toward the "module has dependency" decision, mirroring the option already present on the Maven variant of the recipe.hasDependency: skips resolved dependencies whoseisDirect()isfalse.findMatching(ResolvedDependency)helper hides the depth-0-vs-recurse fork so the loop body stays flat.getPom().getRequestedDependencies()on Maven,c.getRequested()on Gradle) are unchanged — those iterate only direct declarations by construction.Test plan
./gradlew test --tests "org.openrewrite.java.dependencies.search.*"locallyOnlyDirectclass covers: Maven direct still matches, Maven transitive skipped, Gradle direct still matches, Gradle transitive skipped, andonlyDirect+invertMarkingcombined (transitive-only modules get the negative marker)