Maven插件整合protocol buffer

来源:互联网 发布:罗马斗兽场 知乎 编辑:程序博客网 时间:2024/06/05 17:10

1. 博客由来:(1)其他博客   (2)2.5.0版本坑了半天,语法已经改变,参考

2. 分析:在这个过程中可以直接使用.exe编译.proto,当然最好使用Maven插件进行编译,出现问题:a)在上述其他博客中没有找到那个插件的一些信息,放弃,但是配置还是可以学习一下; b)在上述2中被版本语法折腾了;c)在执行compile过程windows中出现 “另一个程序正在使用此文件,进程无法访问”,在google中翻墙未解决

3.解决方案:

首先,给出自己的pom文件以供参考

<dependencies>        <dependency>            <groupId>io.grpc</groupId>            <artifactId>grpc-all</artifactId>            <version>0.13.2</version>        </dependency>        <dependency>            <groupId>io.grpc</groupId>            <artifactId>grpc-protobuf</artifactId>            <version>1.4.0</version>        </dependency>    </dependencies>    <build>        <extensions>            <extension>                <groupId>kr.motd.maven</groupId>                <artifactId>os-maven-plugin</artifactId>                <version>1.4.1.Final</version>            </extension>        </extensions>        <plugins>            <plugin>                <groupId>org.xolstice.maven.plugins</groupId>                <artifactId>protobuf-maven-plugin</artifactId>                <version>0.5.0</version>                <configuration>                    <!--                      The version of protoc must match protobuf-java. If you don't depend on                      protobuf-java directly, you will be transitively depending on the                      protobuf-java version that grpc depends on.                    -->                    <protocArtifact>com.google.protobuf:protoc:3.3.0:exe:${os.detected.classifier}</protocArtifact>                    <pluginId>grpc-java</pluginId>                    <pluginArtifact>io.grpc:protoc-gen-grpc-java:1.4.0:exe:${os.detected.classifier}</pluginArtifact>                    <!--<outputDirectory>${basedir}/src/main/java</outputDirectory>-->                    <!--<clearOutputDirectory>false</clearOutputDirectory>-->                </configuration>                <executions>                    <execution>                        <goals>                            <goal>compile</goal>                            <goal>compile-custom</goal>                        </goals>                    </execution>                </executions>            </plugin>        </plugins>    </build>

其次,在编译.proto中如果出现错误,可能是语法问题,V3.0以上 语法,可能是导包问题(原来只是未导入grpc-protobuf

最后,遇到问题别怕,多google 偷笑

原创粉丝点击