In my app, whenever I add @Nullable
(which imports from org.springframework.lang.Nullable
) to any of the fields, I get a build warning:
Warning:java: unknown enum constant javax.annotation.meta.When.MAYBE reason: class file for javax.annotation.meta.When not found
@NonNull
and other null safety annoations from spring compile without any warnings as its implementation doesn't import import javax.annotation.meta.When
.
The application runs just fine but the warning is just annoying. I am using spring boot 2.1.0
and java version 1.8.0_191
This warning is caused by the javax.annotation.meta.When
enum not being available to your projects runtime (org.springframework.lang.Nullable
references this enum but it is not made available automatically). You need to bring in a JSR305 implementation to fix this warning.
the Google find bugs repo includes a JSR305 implementation that should fix the problem: https://mvnrepository.com/artifact/com.google.code.findbugs/jsr305
since you are using gradle, add the dependency to your build.gradle
script:
...
dependencies {
...
// https://mvnrepository.com/artifact/com.google.code.findbugs/jsr305
implementation 'com.google.code.findbugs:jsr305:3.0.2'
...
}
...
do a clean build and the error should go away
If you do not want to use the com.google.code.findbugs
group's artifact you can try another from this list:
https://mvnrepository.com/search?q=JSR305
references:
it's bothered me too. just try this in your pom:
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>3.0.1</version>
</dependency>
it's work for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With