15

In our open source constraint solver (OptaPlanner), I want to use @NonNull to make it more Kotlin friendly and clearer to use from Java, too.

spring-core already uses @NonNull, for example in this code. They effectively state for every method parameter if it's nullable or not, as explained here.

Which maven/gradle dependency should I use to have the class javax.annotation.Nonnull in my classpath? Which one do the spring guys use? For example, I don't see the findbugs JSR-305 jar in their dependency list.

(And can I have it as an optional dependency to avoid bloating my user's classpath?)

Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120
  • org.springframework.lang.NonNullApi Should be used at package level in association with org.springframework.lang.Nullable annotations at parameter and return value level. org.springframework.lang.Nullable Should be used at parameters, return values and optionally field level in association with NonNullApi package-level annotations. – wholenewstrain Dec 19 '18 at 01:30
  • I need a neutral jar. I am not going to drag in spring from `optaplanner-core` (only in `optaplanner-spring-boot-starter` which provides seamless integration) – Geoffrey De Smet Apr 28 '20 at 08:04
  • The following answer suggests that JSR 305 is not the way to go, as it is "Dormant": https://stackoverflow.com/questions/2289694/what-is-the-status-of-jsr-305 – Lukáš Petrovický Jul 03 '20 at 11:08

1 Answers1

7

I would say that https://mvnrepository.com/artifact/com.google.code.findbugs/jsr305 should be your artifact of choice for this, as it's probably the most commonly used and properly maintained.

Piotr Wilkin
  • 3,446
  • 10
  • 18