0

我正在尝试了解 gRPC。这是我的 pom 文件。

    <dependencies>
        <dependency>
            <groupId>com.google.protobuf</groupId>
            <artifactId>protobuf-java</artifactId>
            <version>3.9.1</version>
        </dependency>
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-netty-shaded</artifactId>
            <version>1.22.1</version>
        </dependency>
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-protobuf</artifactId>
            <version>1.22.1</version>
        </dependency>
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-stub</artifactId>
            <version>1.22.1</version>
        </dependency>
        <dependency>
            <groupId>javax.annotation</groupId>
            <artifactId>javax.annotation-api</artifactId>
            <version>1.3.2</version>
        </dependency>
    </dependencies>
    <build>
        <extensions>
            <extension>
                <groupId>kr.motd.maven</groupId>
                <artifactId>os-maven-plugin</artifactId>
                <version>1.5.0.Final</version>
            </extension>
        </extensions>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.xolstice.maven.plugins</groupId>
                <artifactId>protobuf-maven-plugin</artifactId>
                <version>0.5.1</version>
                <configuration>
                    <protocArtifact>
                        com.google.protobuf:protoc:3.0.0-beta-2:exe:${os.detected.classifier}
                    </protocArtifact>
                    <pluginId>grpc-java</pluginId>
                    <pluginArtifact>
                        io.grpc:protoc-gen-grpc-java:0.14.0:exe:${os.detected.classifier}
                    </pluginArtifact>
                    <protoSourceRoot>
                        ${basedir}/src/main/proto
                    </protoSourceRoot>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>compile-custom</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

我总是不断收到编译错误说annotation @io.grpc.ExperimentalApi is missing a default value for the element 'value'

源是这样生成的。

  public static interface DummyService {
  }

  @io.grpc.ExperimentalApi
  public static abstract class AbstractDummyService implements DummyService, io.grpc.BindableService {

    @java.lang.Override public io.grpc.ServerServiceDefinition bindService() {
      return DummyServiceGrpc.bindService(this);
    }
  }

如何解决这个问题?

4

1 回答 1

1

配置protobuf-maven-plugin为使用io.grpc:protoc-gen-grpc-java:0.14.0:exe:${os.detected.classifier}. 0.14.0 是古老的,是 1.0 之前的版本。我建议使用与protoc-gen-grpc-java其他io.grpc依赖项相同的版本,在本例中为 1.22.1。

因此,您应该将pluginArtifact部分更改为:

<pluginArtifact>
    io.grpc:protoc-gen-grpc-java:1.22.1:exe:${os.detected.classifier}
</pluginArtifact>
于 2019-08-14T16:28:52.100 回答