bazelbuild / bazelbuild/bazel

Support `runtime_deps` in `java_plugin` rule

Open
#16,777 10 comments 0 reactions 0 assignees View on GitHub
P4 stale team-Rules-Java type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

### Description of the feature request:

As of Bazel 5.3.2, the [java_plugin](https://bazel.build/reference/be/java#java_plugin) documentation mentions that:
> Arguments are identical to [java_library](https://bazel.build/reference/be/java#java_library), except for the addition of the processor_class argument.

... but this is not true for `runtime_deps`:
> no such attribute 'runtime_deps' in 'java_plugin' rule

Would it be possible to support this argument there to allow passing dependencies that only make sense for the execution of the annotation processor?

### What underlying problem are you trying to solve with this feature?

When registering an existing annotation processor ([jmh](https://github.com/openjdk/jmh), [immutables](https://github.com/immutables/immutables), etc.), there is no need to pass any `srcs` (sources to compile) and thus no `deps` (compile-time dependencies), but `deps` is currently the only way to pass the jar in which the `processor_class` resides.

Having the possibility to pass the annotation processor jar through `runtime_deps` in this case would also prevent some unused dependency detection/removal tools ([unused_deps](https://github.com/bazelbuild/buildtools/tree/master/unused_deps), [unused-deps-py](https://github.com/bookingcom/buildtools/tree/master/unused_deps_py)) from spotting it when passed through `deps`.

### Which operating system are you running Bazel on?

Ubuntu 22.04.1 LTS (GNU/Linux)

### What is the output of `bazel info release`?

release 5.3.2

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

_No response_

### What's the output of `git remote get-url origin; git rev-parse master; git rev-parse HEAD` ?

_No response_

### Have you found anything relevant by searching the web?

_No response_

### Any other information, logs, or outputs that you want to share?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the java_plugin rule and compare its supported attributes with java_library, focusing on runtime_deps. Check the annotation-processor use case described for JMH or Immutables, then add coverage showing that a processor jar supplied through runtime_deps is available at execution time without being treated as a compile dependency.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.