Skip to content

[gazelle] Allow other plugins to also contribute to class location#415

Open
shs96c wants to merge 3 commits into
bazel-contrib:mainfrom
shs96c:contributing-plugins
Open

[gazelle] Allow other plugins to also contribute to class location#415
shs96c wants to merge 3 commits into
bazel-contrib:mainfrom
shs96c:contributing-plugins

Conversation

@shs96c
Copy link
Copy Markdown
Collaborator

@shs96c shs96c commented Feb 3, 2026

When multiple rules create a "split package", Gazelle needs class-level resolution to determine which rule provides which class. Previously, only the built-in Java plugin could participate in this resolution via the internal classExportCache. Other gazelle plugins which generate java classes (such as a possible one for Wire) could not.

This PR introduces a SharedClassCache in config.Exts that external plugins can populate with their class information:

// In external plugin's GenerateRules:
cache := javaconfig.GetOrCreateSharedClassCache(args.Config)
cache["//pkg:my_wire_rule"] = javaconfig.SharedClassInfo{
    Classes:  []string{"com.example.MyGeneratedClass"},
    TestOnly: false,
}

The Java plugin's buildPackageClassIndex now consults both:

  1. Internal classExportCache (for java_library rules)
  2. SharedClassCache (for external plugin rules)

This allows plugins for other languages (such as a possible one for
[Wire](https://square.github.io/wire/)) to contribute Java classes
and packages to the dependency resolution.
@shs96c shs96c force-pushed the contributing-plugins branch from 6e231e4 to 65f296a Compare February 3, 2026 16:51
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.

1 participant