-
Notifications
You must be signed in to change notification settings - Fork 15.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modular Java #16502
base: main
Are you sure you want to change the base?
Modular Java #16502
Conversation
Fixes and closes protocolbuffers#16169 by pinning the build to Bazel `6.3.2`. Signed-off-by: Sam Gammon <[email protected]>
Fixes and closes protocolbuffers#16170 by adding missing test-gen mappings and exclusions. - fix: missing test-gen mappings - fix: missing test exclusions Signed-off-by: Sam Gammon <[email protected]>
Signed-off-by: Sam Gammon <[email protected]>
Signed-off-by: Sam Gammon <[email protected]>
Signed-off-by: Sam Gammon <[email protected]>
Signed-off-by: Sam Gammon <[email protected]>
is this PR under consideration for being merged in the project ? |
@sgammon Thank you for the proposal. |
@googleberg I'm happy to try and make this a smaller PR, yes. I'll need to review my code in order to answer your other comments with context. Generally speaking I try to keep PRs with Google's software as small as possible, though, so if something is in this PR, I am probably under the impression that it is needed. If you can see routes toward making things smaller that I don't see, please let me know! |
Summary
This changeset attempts to discover the minimal set of changes necessary to add
module-info.java
definitions to Protocol Buffers. Fixes and closes #16133.This is a draft PR for now. I'm looking for feedback and to setup an integration testsuite downstream with popular Protobuf-based projects to make sure things work as expected.
Note
Re-filing after a bad rebase on #16178.
PR Tree
This PR is applied on top of the following:
6.3.2
#16171Relevant PRs + issues upstream
annotations
google/error-prone#4311annotations
module google/j2objc#2302JAR Structure
JARs issued as part of the Protobuf Java release now have
Multi-Release: true
instead ofAutomatic-Module-Name
within theirMANIFEST.MF
, making them eligible to be considered as Multi-Release JARs (or, MRJARs). Such JARs can include amodule-info.class
without interfering with bytecode targeting at JDK8 or earlier, where modules are not supported yet. These JARs are thus called "modular MRJARs."For example, after building Protobuf Java with
bazel build //java:release
,vim bazel-bin/java/core/amended_lite_mvn-project.jar
shows:JAR structure:
In the
MANIFEST.MF
:Modular Java downstream
For projects that build with Protobuf Java on the
classpath
, no change is experienced by the end-user; for projects which build onmodulepath
:Open module
Protobuf, Protobuf Util, and Protobuf Kotlin are expressed as
open
modules. This is the case because Protobuf Java is often used reflectively by library consumers. By default, all packages provided by Modular Java protobuf artifacts areopen
as a result.Exports + Lite Variants
Protobuf Java Core, Protobuf Java Util, and Protobuf Kotlin all reside in one package path each, which is extremely lucky and convenient for Modular Java because there is no split package problem.
Kotlin Lite/Kotlin and Java Core/Java Lite are meant to be used exclusively within the
classpath
, but there is no enforcement possible for this case from the compiler or VM, at least not in a consistent way across environments. Building on themodulepath
solves this because Kotlin Lite/Kotlin and Java Core/Java Lite share a module coordinate and export an identical package path.Thus, only one of (Kotlin/Kotlin Lite) and (Java Core/Java Lite) can be used at a time when building on the
modulepath
. This guarantee is enforced by the compiler and by the JVM at runtime.Changelog
rules_kotlin