Skip to content

Support stripping protobuf-java jars in java_export when using protoc via toolchain#1481

Merged
shs96c merged 1 commit into
bazel-contrib:masterfrom
thirtyseven:master
Nov 19, 2025
Merged

Support stripping protobuf-java jars in java_export when using protoc via toolchain#1481
shs96c merged 1 commit into
bazel-contrib:masterfrom
thirtyseven:master

Conversation

@thirtyseven
Copy link
Copy Markdown
Contributor

@thirtyseven thirtyseven commented Nov 18, 2025

Fixes #1480.

This PR should have tests, but I'm not sure of the best way to add them since ideally we want to run tests/integration/java_export in both toolchain and non-toolchain mode (with and without --incompatible_enable_proto_toolchain_resolution) and this doesn't seem easy with the current test suite design. Would like validation about this approach before committing to adding support for this to the test suite.

@shs96c
Copy link
Copy Markdown
Collaborator

shs96c commented Nov 18, 2025

This is what the excluded_workspaces attribute of java_export is for. Can't we just add the workspace to the default list?

@thirtyseven
Copy link
Copy Markdown
Contributor Author

thirtyseven commented Nov 18, 2025

This is what the excluded_workspaces attribute of java_export is for. Can't we just add the workspace to the default list?

When using the Java proto lang toolchain, the protobuf runtime jar can come from any workspace. For example, in our repo we have it set to be @maven//:com_google_protobuf_protobuf_java and in the toolchains_protoc example it's @protobuf-java//jar.

I updated the linked ticket with a bit more detail.

The alternative would be to tell users to manually specify excluded_workspaces for every java_export when using a Java proto_lang_toolchain, but that seems not very user-friendly and not in the spirit of toolchains.

@thirtyseven thirtyseven changed the title Support stripping protobuf-java jars when using protoc via toolchain Support stripping protobuf-java jars in java_export when using protoc via toolchain Nov 18, 2025
Comment thread private/rules/maven_project_jar.bzl
Comment thread private/rules/maven_project_jar.bzl
Copy link
Copy Markdown
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!

Comment thread private/rules/maven_project_jar.bzl
Comment thread private/rules/maven_project_jar.bzl
@shs96c shs96c merged commit 9213ad6 into bazel-contrib:master Nov 19, 2025
6 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.

protobuf-java runtime is not removed from java_export targets when using --incompatible_enable_proto_toolchain_resolution and a custom runtime jar

2 participants