Skip to content

Conversation

@Ignas
Copy link
Contributor

@Ignas Ignas commented Aug 30, 2023

When preserving runtime dependencies of existing rules use the new rule name if it was remapped.

Copy link
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

It looks like you're missing a (empty) file at java/gazelle/testdata/lib_with_runtime_deps_and_map_kind/WORKSPACE which means this isn't being picked up as a new test?

And if you add that, I think there's an extra trailing -data and the end of java/gazelle/testdata/lib_with_runtime_deps_and_map_kind/expectedStderr.txt

Otherwise, happy to merge - thanks!

@Ignas
Copy link
Contributor Author

Ignas commented Aug 30, 2023

Ahh, indeed, sorry, lost the WORKSPACE during migration of the patch from one repo to another, thanks for spotting it.

Copy link
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

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

Thanks!

@illicitonion illicitonion merged commit 98138f2 into bazel-contrib:main Aug 31, 2023
shs96c pushed a commit that referenced this pull request Nov 6, 2025
… using mapped kinds (#386)

# 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 #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 #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
bazel-contrib/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_suite` →
`generic_java_test_suite`)
- Test suites with existing runtime_deps that need to be preserved
- JUnit5 test suites with custom runtime dependencies
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