Fix attribute merging issues on java_library and java_test_suite when using mapped kinds #386
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
This PR resolves two specific issues when using mapped kinds:
java_library:depsare not updated to include new or remove unnecessary dependencies.java_test_suite:runtime_depsare always removed. (Reported in Gazelle removes runtime_deps from junit4 test suites #337)Problem
When using kind mappings for
java_libraryandjava_test_suite, Gazelle would fail to merge attributes because:GenerateRulesis returning the mapped kind instead ofjava_library. Gazelle core can not merge the attributes because it doesn't haveKindInfofor the mapped kind.collectRuntimeDeps()is checking both the rule kind and name, which will fail to find existing rules that have been mapped to a different kindgenerateJavaTestSuite()only setsruntime_depsinside the JUnit5 conditional block, causing runtime_deps to be lost when JUnit5 isn't detectedSolution
GenerateRulesis updated to return ajava_libraryrule. The removed logic was added in Handle java_library being remapped with map_kind #199 because the second issue was seen onjava_library.collectRuntimeDeps()is updated to only check the rule name, not the kind. This is inline with the discussion at map_kind - apply inverse mapping torule.Filepassed toGenerateRulesbazel-gazelle#560 about the same issue.generateJavaTestSuite()is updated to always setruntime_deps, even when JUnit5 isn't detected.Testing
All existing tests pass, and new test cases verify the fix works correctly for:
java_test_suite→generic_java_test_suite)