Skip to content

Propagate .jdeps for java_import#363

Open
fmeum wants to merge 1 commit into
bazelbuild:masterfrom
fmeum:java-import-reduced-classpath
Open

Propagate .jdeps for java_import#363
fmeum wants to merge 1 commit into
bazelbuild:masterfrom
fmeum:java-import-reduced-classpath

Conversation

@fmeum

@fmeum fmeum commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Downstream Java compilation actions need accurate .jdeps files for their reduced classpath optimization. With this change, java_import now always runs ImportDepsChecker to generate this file, but possibly suppresses its outputs.

Fixes #362

@fmeum fmeum force-pushed the java-import-reduced-classpath branch from 1c5b6ea to bbf650b Compare June 30, 2026 10:08
@fmeum fmeum changed the title Make java_import participate in Java classpath reduction Propagate .jdeps for java_import Jun 30, 2026
@fmeum fmeum force-pushed the java-import-reduced-classpath branch 2 times, most recently from bd8f649 to 1de17e5 Compare June 30, 2026 10:18

# Default java_toolchain parameters
_BASE_TOOLCHAIN_CONFIGURATION = dict(
deps_checker = Label("@remote_java_tools//:ImportDepsChecker"),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a breaking change for Bazel as the hardcoded mode is error. Can I add a new attribute that makes it configurable on the toolchain level? I can set the default to silence to match the current behavior or to error as a breaking change with a simple migration.

Are you precompiling the tool to a native image at Google?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Are you precompiling the tool to a native image at Google?

It's a prebuilt jar that runs on the JVM, but it's also a validation action that is not on the critical path (#362 (comment)).

Using a native image seems like a good idea if it's going to run as a non-validation action so the .jdeps can be used for reduced classpaths.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can I add a new attribute that makes it configurable on the toolchain level?

Bazel supports tags = ["incomplete-deps"] on java_import. Having a real attribute (on the toolchain and/or individual java_imports) is probably better than leaning on tags for this.

cc @hvadehra

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My main concern is that external repos using java_import would be very difficult to opt out unless there is a global (toolchain) switch.

@fmeum fmeum force-pushed the java-import-reduced-classpath branch 4 times, most recently from 1206db6 to 14e031c Compare June 30, 2026 10:30
With `--experimental_java_classpath=bazel_no_fallback` (and as a double-compilation
pessimization under the default `bazel` mode), a `java_import` defeated the reduced-classpath
optimization for every target depending on it. Unlike a `java_library` header jar, which is built
by turbine (emitting a jdeps and repackaging the supertype closure), a `java_import` interface jar
is built by ijar and contributed no compile-time dependency artifact, so downstream reduced
classpaths pruned the import's transitive jars.

`java_import` now runs `ImportDepsChecker` (newly wired into the default toolchain's `deps_checker`)
over its jars and propagates the resulting jdeps proto as `compile_jdeps`. The checker records the
full transitive supertype closure, so this is correct for supertype chains of any depth. It runs in
`silence` mode (purely additive, never a new build failure) and only when the import has
deps/exports; the jdeps is consumed lazily.

Fixes bazelbuild#362
@fmeum fmeum force-pushed the java-import-reduced-classpath branch from 14e031c to 08211fd Compare June 30, 2026 10:31
@fmeum

fmeum commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

@cushon

@fmeum fmeum marked this pull request as ready for review June 30, 2026 10:34
@fmeum fmeum requested review from a team and hvadehra as code owners June 30, 2026 10:34
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.

classpath reduction defeated by transitive java_import dependencies

2 participants