Skip to content

Add onlyDirect option to ModuleHasDependency - #199

Open
steve-aom-elliott wants to merge 2 commits into
mainfrom
add-only-direct-module-has-dependency
Open

steve-aom-elliott wants to merge 2 commits into
mainfrom
add-only-direct-module-has-dependency

Conversation

@steve-aom-elliott

Copy link
Copy Markdown
Contributor

Summary

Adds an onlyDirect option to org.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.

  • Maven branch of hasDependency: skips resolved dependencies whose isDirect() is false.
  • Gradle branch: a small findMatching(ResolvedDependency) helper hides the depth-0-vs-recurse fork so the loop body stays flat.
  • Requested-fallback loops (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.*" locally
  • New nested OnlyDirect class covers: Maven direct still matches, Maven transitive skipped, Gradle direct still matches, Gradle transitive skipped, and onlyDirect + invertMarking combined (transitive-only modules get the negative marker)

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 steve-aom-elliott added enhancement New feature or request recipe labels Sep 24, 2026
@steve-aom-elliott
steve-aom-elliott marked this pull request as ready for review September 24, 2026 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request recipe

Projects

Status: Ready to Review

Development

Successfully merging this pull request may close these issues.

1 participant