Skip to content

Fix AddDependency bypassing onlyIfUsing with explicit config#6834

Merged
timtebeek merged 3 commits intomainfrom
timtebeek/fix-issue-6833
Feb 27, 2026
Merged

Fix AddDependency bypassing onlyIfUsing with explicit config#6834
timtebeek merged 3 commits intomainfrom
timtebeek/fix-issue-6833

Conversation

@timtebeek
Copy link
Copy Markdown
Member

@timtebeek timtebeek commented Feb 26, 2026

Summary

Fixes a bug where AddDependency bypassed the onlyIfUsing per-project type check when configuration was explicitly provided. This caused dependencies to be added to all build.gradle files — including buildSrc/build.gradle — rather than only projects that actually use the specified type.

Changes

  • Split the single guard condition in AddDependency.getVisitor() into two separate checks: one for per-project type usage (always applied when onlyIfUsing is set) and one for configuration inference (only when configuration is not explicit).

  • Added test case doesNotAddToProjectNotUsingTypeWhenConfigurationIsExplicit to verify the fix: a multi-project scenario where only project1 uses the target type and should receive the dependency.

  • Fixes Issue discovered on buildSrc/build.gradle with Update Gradle wrapper #6833

…xplicit

When AddDependency is configured with both an explicit configuration (e.g., testRuntimeOnly) and onlyIfUsing (e.g., org.junit.jupiter.api.Test), the per-project type usage check is bypassed. This causes dependencies to be added to all build.gradle files, including buildSrc/build.gradle, rather than only projects that actually use the specified type.

Split the single guard condition into two separate checks: always check per-project type usage when onlyIfUsing is set, and only check configurationsByProject when configuration needs to be inferred. Add test to verify the fix.

Fixes #6833
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Feb 26, 2026
@timtebeek timtebeek marked this pull request as draft February 26, 2026 15:43
@timtebeek timtebeek marked this pull request as ready for review February 26, 2026 21:26
@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite Feb 26, 2026
@timtebeek timtebeek merged commit c32d382 into main Feb 27, 2026
1 check passed
@timtebeek timtebeek deleted the timtebeek/fix-issue-6833 branch February 27, 2026 12:01
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Issue discovered on buildSrc/build.gradle with Update Gradle wrapper

2 participants