美文网首页
MAC OS 下protobuf 2.6.1 版本编译安装及pr

MAC OS 下protobuf 2.6.1 版本编译安装及pr

作者: 天高s | 来源:发表于2018-10-11 14:59 被阅读0次

新接手一个项目,使用 protobuf-java 2.6.1 的版本,要新加字段,蛋疼

先用 homebrew 装一个试试

$homebrew install protobuf

结果是失败了,默认安装了最新版的 3.6,生成的 Entity 文件无法通过编译,要改的话还要适配所有使用的地方,不现实,只好找对应版本的生成了。

下面是成功生成的过程。

配置 maven 插件

    <build>
        ...
        <plugins>
            <plugin>
                <groupId>org.xolstice.maven.plugins</groupId>
                <artifactId>protobuf-maven-plugin</artifactId>
                <version>0.5.1</version>
                <extensions>true</extensions>
                <configuration>
                    <!-- .proto 文件路径 -->
                    <protoSourceRoot>${project.basedir}/proto</protoSourceRoot>
                    <!-- 输出路径 -->   
               <outputDirectory>${project.basedir}/src/main/java</outputDirectory>
                    <!--设置是否在生成java文件之前清空outputDirectory的文件,默认值为true,设置为false时也会覆盖同名文件-->
                    <clearOutputDirectory>false</clearOutputDirectory>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Protobuf2.6.1 源码包下载

Protocol Buffers v2.6.1

Protobuf2.6.1 编译安装

cd 到解压目录下

$ ./configure
$ make
$ make check
$ make install
$ protoc --version

执行 maven 编译命令

IDEA maven 窗口 编译输出

搞定收工

相关文章

网友评论

      本文标题:MAC OS 下protobuf 2.6.1 版本编译安装及pr

      本文链接:https://www.haomeiwen.com/subject/fiybaftx.html