Guava r07, GWT and javax.annotation.Nullable

前端 未结 3 1171
遥遥无期
遥遥无期 2020-12-14 17:22

I\'m trying to use Guava in a GWT project without success (a HashMultimap, to be precise). I get a never-ending list of stacktraces for classes:

  • com.google.co
相关标签:
3条回答
  • 2020-12-14 17:32

    You need to obtain the JSR 305 JAR, but in addition, you need to include the @Nullable annotation source code as food for the GWT compiler.

    Assuming your project is under com/example/myproject/ Create a file: com/example/myproject/annotation/javax/annotation/Nullable.java With the following content:

    package com.example.myproject.annotation.javax.annotation;
    
    import java.lang.annotation.Documented;
    import java.lang.annotation.Retention;
    import java.lang.annotation.RetentionPolicy;
    
    import javax.annotation.Nonnull;
    import javax.annotation.meta.TypeQualifierNickname;
    import javax.annotation.meta.When;
    
    @Documented
    @TypeQualifierNickname
    @Nonnull(when = When.UNKNOWN)
    @Retention(RetentionPolicy.RUNTIME)
    public @interface Nullable {
    
    }
    

    Add the line to MyProject.gwt.xml:

    <super-source path="annotation"/>
    

    And you're good to go.

    0 讨论(0)
  • 2020-12-14 17:43

    Hum... I think it's the jsr305 you're looking for. Take a look at

    http://www.findjar.com/jar/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar.html

    It must be better here: http://code.google.com/p/guava-libraries/source/browse/#svn/trunk/lib where I see the @Nullable annotation

    0 讨论(0)
  • 2020-12-14 17:46

    As written above, the problem appears to be solved when using guava 10.0.1, which has an additional dependency on the JSR305 library.

    Alternatively, the ID of the missing library to add to Maven is com.google.code.findbugs:jsr305:1.3.9, so the build configuration should be fixed by adding the following dependency to pom.xml in the appropriate place (warning - I didn't test this):

    <dependency>
        <groupId>com.google.code.findbugs</groupId>
        <artifactId>jsr305</artifactId>
        <version>2.0.1</version>
        <scope>provided</scope>
    </dependency>
    

    Update: User @ips suggested adding <scope>provided</scope> since the jsr305 jar isn't needed at runtime, and updating to version 2.0.1. I know that the first change makes sense, and I guess that the version update also does. In my experience, using <scope>provided</scope> created problems for Scala, but that's a separate issue.

    0 讨论(0)
提交回复
热议问题