Fix AddDependency bypassing onlyIfUsing with explicit config#6834
Merged
Fix AddDependency bypassing onlyIfUsing with explicit config#6834
Conversation
…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
steve-aom-elliott
approved these changes
Feb 26, 2026
3 tasks
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
Fixes a bug where
AddDependencybypassed theonlyIfUsingper-project type check whenconfigurationwas explicitly provided. This caused dependencies to be added to allbuild.gradlefiles — includingbuildSrc/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 whenonlyIfUsingis set) and one for configuration inference (only when configuration is not explicit).Added test case
doesNotAddToProjectNotUsingTypeWhenConfigurationIsExplicitto 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.gradlewithUpdate Gradle wrapper#6833