-
Notifications
You must be signed in to change notification settings - Fork 1.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
Compiling on Module Path with -Werror and -Xlint:all #3437
Comments
Please submit a PR, 🥺 . I found out about your
A |
Thanks for the quick response @ppkarwasz. I'll prepare a PR for the Gradle Metadata in the next days.
Ah yes. I did not think about that. Luckily, if you would add them as
This would be in line with the |
We use the BND JPMS Libraries to generate our IMHO annotations that are not visible at runtime do not need to be mentioned in the |
See apache#3437 for details. Signed-off-by: Jendrik Johannes <[email protected]>
See apache#3437 for details. Signed-off-by: Jendrik Johannes <[email protected]>
See apache#3437 for details. Signed-off-by: Jendrik Johannes <[email protected]>
My understanding of the argument why annotations with As OSGi is only about runtime, it's no surprise that BND does not care about this as well. It took me some time and source code reading / debugging of BND's JPMS support, but I found the switch to add additional Only having both things – Gradle Metadata for Here is a PR that proposes to add both: #3450 |
See apache#3437 for details. Signed-off-by: Jendrik Johannes <[email protected]>
This is about getting an error like the following when compiling with a
module-info.java
and the compiler flags-Xlint:all
and-Werror
:The error is triggered by using classes from Log4j that use annotations on public members from the annotation libraries indicated in the error message. There are two layers of missing dependencies that cause this:
com.google.errorprone:error_prone_annotations:2.36.0
) is not on the Classpath/Module Pathcom.google.errorprone.annotations
) is not defined asrequire static
in the correspondingmodule-info.class
of Log4jFor (1) it's debatable if it can be fixed in a good way, as POM does not have a scope that resembles Gradle's compileOnlyApi scope: visible transitively but ONLY on the compile classpath.
For (2) you can argue that it is a bug, because if the code of Log4j would be compiled on the Module Path (i.e. with the compiler checking the
module-info.java
) it would not compile.Workarounds for users
(1)
compileOnly
(<provided>
) to your own project.(2)
--add-reads
argumentsmodule-info.class
itself (possible in Gradle with plugin)This is a minimal example showing all the annotation libraries that need to be "patched in":
https://github.com/jjohannes/gradle-demos/blob/main/log4j-metadata/build.gradle.kts
Possible improvements in Log4j
(1) This was already discussed here. The dependencies marked as
<provided>
here would need to be switched to<compile>
. But that has the unwanted effect that ALL users will get them as unnecessary RUNTIME dependencies.There is the option to publish additional Gradle Metadata that supports the
compileOnlyApi
scope. If you are interested, I can make a contribution for that as I maintain the Maven plugin for publishing such metadata with Maven (it's used by Jackson for example). But I can understand if you don't want to have additional complexity in your build setup.(2) Maybe you can check if the additional requires could be added to all
module-info
:*
requires static
works also, but conceptuallyrequires static transitive
feels more correct as the annotations are transitively visible.All of this can also be avoided by turning of the
classfiles
line check ofjavac
...I can understand if there is nothing you can/want to do at this point. Then, feel free to close this issue.
Having this written down can be helpful for users who run into this in any case.
If you want to do something I can help with, let me know.
The text was updated successfully, but these errors were encountered: