Bazel incorrectly caches resources of java_plugins
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the bug:
I have a Java annotation processor defined in a `java_plugin` with some JSON file `resources`. This generator is applied to a datamodel `java_library` and generates a `.java` file based on the JSON file if the `java_library` contains a certain annotation.
After I edit the JSON file, a subsequent `bazel build` does not generate Java source files using the updated version of the file - it instead uses a cached old version. This is most apparent when there is a compile error as a result of the original JSON file, and a subsequent change to the file does not lead to the error going away.
### Which category does this issue belong to?
Core, Java Rules
### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Please see minimal example repository here: https://github.com/SimplyTheOther/Bazel-bug-replication
1. Execute `bazel build //datamodel:station-datamodel`
2. Note that compilation fails, saying `error: cannot find symbol @FakeAttr public class S3Parameter {}`
3. Delete the line saying `@FakeAttr` from `datamodel/src/main/resources/generator/model/S3Parameter.json`
4. Execute `bazel build //datamodel:station-datamodel`
5. Note that compilation fails with the same error
6. Execute `bazel clean`
7. Execute `bazel build //datamodel:station-datamodel`
8. Note that compilation succeeds and that the generated `S3Parameter.java` file does not contain any reference to `@FakeAttr`
You can also repeat in the opposite direction, i.e. going from an `S3Parameter.json` that contains no `@FakeAttr`, and seeing that it erroneously continues to compile when the line is added.
### Which operating system are you running Bazel on?
Linux (also replicated on macOS)
### What is the output of `bazel info release`?
release 8.0.0
### 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 HEAD` ?
```text
https://github.com/SimplyTheOther/Bazel-bug-replication.git
314789ab0a50cbe870d6499c5517fe39b2a27b76
```
```
### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.
_No response_
### Have you found anything relevant by searching the web?
No
### Any other information, logs, or outputs that you want to share?
_No response_
Contributor guide
Research direction
Reproduce the failure with `bazel build //datamodel:station-datamodel` using the linked minimal repository, editing `datamodel/src/main/resources/generator/model/S3Parameter.json` between builds. Trace how the `java_plugin` resource reaches generation and cache invalidation, then verify that changing the JSON causes `S3Parameter.java` to be regenerated without `bazel clean` and that both annotation directions compile correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100