Java – why do I need to add artifact jsr305 to use guava 14?
When looking up the information of stack overflow, I saw a question similar to mine, but there was no real answer here
I need to change my Maven project from guava 11.0 2 migrate to guava 14 or higher (I need rangeset) I updated my Maven POM with dependency:
<dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>14.0</version> </dependency>
Then I run the Maven build and get this error:
[ERROR] xxx.java: cannot find symbol [ERROR] symbol : class Nonnull [ERROR] location: package javax.annotation
I have carefully observed this annotation, which is provided by JSR 305, which relies on guava 11.0 2. As reported by MVN repository
I find it strange that guava 14 also relies on JSR 305 as the MVN repository
If I add JSR dependencies to my POM, the compilation works normally:
<dependency> <groupId>com.google.code.findbugs</groupId> <artifactId>jsr305</artifactId> <version>1.3.9</version> <scope>provided</scope> </dependency>
However, if guava already depends on it, why do I have to add this dependency to my POM? It looks more like a solution than a solution. I prefer to understand and make things clear
Thank you for your participation
Solution
The reason you need to add it as a dependency is because guava 14 defines a dependency in its POM, as follows:
<dependency> <groupId>com.google.code.findbugs</groupId> <artifactId>jsr305</artifactId> <version>1.3.9</version> <scope>provided</scope> </dependency>
The important part of your question is that < scope > provides < / scope > lines
Since Maven website, the dependencies provided by them are described as follows:
So it's basically because guava has set this as a dependency. They want anyone who uses guava to provide this dependency. That's what you have to do
In guava 11.0 2, it is a normal compilation dependency, so you don't have to provide it in your own project
The change is in guava 13 From the release notes: