Can we use JSR 308 type annotions in Java 7 project (like @NonNull
, ...) ? If yes, what is the related maven dependency ?
Yes... sort of. Type annotations were introduced in Java 8, so they don't work at all in Java 7. And the OpenJDK implementation of JSR 308, for example, is in the OpenJDK 8 JDK. So you can't use that.
But you could use the checker framework which gets around this by allowing you to comment out type annotations in Java 7, but still use them. Setup is described here. You'll need the following maven dependency:
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker</artifactId>
<version>1.9.12</version>
</dependency>