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
Java annotation processors do not have access to resources #12964
Comments
@lgalfaso What does it fail with? It seems that you pasted wrong text into the description. Could you provide also sample code for processor? Do I understand correctly that you're accessing downstream resources from the processor? If I understand this correctly, then this looks like a fishy design to me; could you support it with some use cases or an OSS annotation processor that does this? |
I believe I might be affected by this with pf4j java_plugin(
name="pf4j_plugin",
processor_class = "org.pf4j.processor.ExtensionAnnotationProcessor",
deps = [
"@maven//:org_pf4j_pf4j",
],
)
java_library(
name = "pf4j",
exported_plugins = [":pf4j_plugin"],
visibility = ["//:__subpackages__"],
exports = [
"@maven//:org_pf4j_pf4j",
],
)
// in app folder
kt_jvm_library(
name = "kotlin",
srcs = glob(["src/main/kotlin/**/*"]),
deps = [
"//:pf4j",
],
) I expect to have |
I think this issue also affects the Spring Boot Configuration Processor. I'm using a According to https://docs.spring.io/spring-boot/docs/current/reference/html/configuration-metadata.html#configuration-metadata.annotation-processor.adding-additional-metadata we can add some custom hand-written properties in a resource resource The documentation suggests:
But it's not clear how to achieve this with Bazel. Perhaps a solution is to provide another I've created an example repo with both Gradle (passing) and Bazel (failing) configurations: https://github.com/Zetten/bazel-java-annotation-processor-resources. Simply |
I ran into this as well. I was able to work around it by using:
from within the processor, which got me the path into the source_output root (I think that's the one, anyway). Since in my particular case the resources were included in the I did, however, run into staleness problems #14095 |
Ran into this issue as well. My current workaround is (1) to expose the resources in question to java_plugin via its "resource_jars" attribute and (2) to let the annotation processor search for the resources within StandardLocation.ANNOTATION_PROCESSOR_PATH. This, of course, requires a separate java_plugin declaration for each library that needs processing. Ugly workaround, but works for me. |
Please reconsider. Needing a separate and my issue #14095 was duped to this only in the hope that this would actually be fixed. |
There's some related history in internal issue b/198685781. One of the options discussed is to do with with a separate attribute on library rules that would make files available to annotation processing, e.g. |
Hello @bdleitner, Thank you for reaching out to us regarding the above issue. Please follow up on the internal issue as mentioned above for more updates and we have reopened the present issue. |
does anyone have a working demo of how to make this possible available on github? I have a usecase I'd like to scan a set of annotations at compile time collect the data into a resource which another library can then consume. the path to accomplish that with bazel semantics + sandboxing is still a bit unclear |
Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team ( |
@bazelbuild/triage not stale |
When executing a Java annotation processor, it does not have access to the resources referenced by the originating class.
Where
target
contains a class that has an annotation that makes reference to a resource in:res
.The resources are attempted to be loaded doing
and if that fails, with
At first, it looks like the issue was that in the classpath there were only java headers/interfaces present, so tried with
--nojava_header_compilation --nouse_ijars
--nojava_header_compilation --nouse_ijars
and creating a dummy class in:res
None worked.
Using bazel release 4.0.0-homebrew
The text was updated successfully, but these errors were encountered: