Skip to content

Conversation

@jeffmace
Copy link
Contributor

Summary

This PR resolves two specific issues when using mapped kinds:

  1. java_library:deps are not updated to include new or remove unnecessary dependencies.
  2. java_test_suite:runtime_deps are always removed. (Reported in Gazelle removes runtime_deps from junit4 test suites #337)

Problem

When using kind mappings for java_library and java_test_suite, Gazelle would fail to merge attributes because:

  1. GenerateRules is returning the mapped kind instead of java_library. Gazelle core can not merge the attributes because it doesn't have KindInfo for the mapped kind.
  2. collectRuntimeDeps() is checking both the rule kind and name, which will fail to find existing rules that have been mapped to a different kind
  3. generateJavaTestSuite() only sets runtime_deps inside the JUnit5 conditional block, causing runtime_deps to be lost when JUnit5 isn't detected

Solution

  1. GenerateRules is updated to return a java_library rule. The removed logic was added in Handle java_library being remapped with map_kind #199 because the second issue was seen on java_library.
  2. collectRuntimeDeps() is updated to only check the rule name, not the kind. This is inline with the discussion at map_kind - apply inverse mapping to rule.File passed to GenerateRules bazel-gazelle#560 about the same issue.
  3. generateJavaTestSuite() is updated to always set runtime_deps, even when JUnit5 isn't detected.

Testing

All existing tests pass, and new test cases verify the fix works correctly for:

  • Test suites with mapped kinds (java_test_suitegeneric_java_test_suite)
  • Test suites with existing runtime_deps that need to be preserved
  • JUnit5 test suites with custom runtime dependencies

Copy link
Collaborator

@shs96c shs96c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you!

@shs96c shs96c enabled auto-merge (squash) November 6, 2025 11:35
@shs96c shs96c merged commit 6876131 into bazel-contrib:main Nov 6, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants