Protobuf和带有Maven的GRPC无法编译

时间:2018-08-19 05:50:40

标签: java maven protocol-buffers grpc

因此,我第一次使用Maven学习grpc和protobuf,但是在生成代码后,生成的Java文件无法编译。我试图在一个单独的Java项目中生成代码(然后我自己拖入了所有的jar,这些jar是从maven存储库下载的),但是该项目以某种方式得以编译。有人知道为什么会这样吗?

Pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>maven</artifactId>
<version>0.0.1-SNAPSHOT</version>

<dependencies>
    <!-- https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java -->
    <dependency>
        <groupId>com.google.protobuf</groupId>
        <artifactId>protobuf-java</artifactId>
        <version>3.6.1</version>
    </dependency>
    <dependency>
        <groupId>io.grpc</groupId>
        <artifactId>grpc-netty-shaded</artifactId>
        <version>1.14.0</version>
    </dependency>
    <dependency>
        <groupId>io.grpc</groupId>
        <artifactId>grpc-protobuf</artifactId>
        <version>1.14.0</version>
    </dependency>
    <dependency>
        <groupId>io.grpc</groupId>
        <artifactId>grpc-stub</artifactId>
        <version>1.14.0</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.xolstice.maven.plugins</groupId>
            <artifactId>protobuf-maven-plugin</artifactId>
            <version>0.5.1</version>
            <configuration>
                <protocArtifact>com.google.protobuf:protoc:3.5.1-1:exe:${os.detected.classifier}</protocArtifact>
                <pluginId>grpc-java</pluginId>
                <pluginArtifact>io.grpc:protoc-gen-grpc-java:1.14.0:exe:${os.detected.classifier}</pluginArtifact>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>compile-custom</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

我得到一些错误:

Feature.java中的“功能层次结构不一致”

在Feature.java中,“ com.google.protobuf.AbstractMessage $ Builder类型无法解析。它是从所需的.class文件中间接引用的”。即使protobuf lib位于项目中,也是如此

“ RouteGuideGrpc.RouteGuideImplBase类型的方法bindService()必须重写超类方法” –即使在api中重写方法,也要在RouteGuideGrpc.java中使用

谢谢!

0 个答案:

没有答案
相关问题