首页  

maven插件编译proto文件     所属分类 maven 浏览量 639
src/main/proto/Person.proto

syntax="proto3"; 
option java_package = "dyyx";   
option java_outer_classname = "PersonProto";   
message Person  { 
  string name = 1;
  int32 age = 2;
} 


<dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java</artifactId> <version>3.11.4</version> </dependency> <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.1</version> <configuration> <protocArtifact> com.google.protobuf:protoc:3.1.0:exe:${os.detected.classifier} </protocArtifact> <pluginId>grpc-java</pluginId> </configuration> <!-- <executions> <execution> <goals> <goal>compile</goal> <goal>compile-custom</goal> </goals> </execution> </executions> --> </plugin> </plugins> </build> compile 阶段 进行 proto文件 编译 <executions> <execution> <goals> <goal>compile</goal> <!--<goal>compile-custom</goal>--> </goals> </execution> </executions> os-maven-plugin 检测 系统属性 譬如 ${os.name} ${os.arch}
mvn protobuf:compile 或者在 idea maven 窗口 选择 指定的插件任务执行 [INFO] --- protobuf-maven-plugin:0.5.1:compile (default-cli) @ maven-proto-demo --- Downloading from alimaven: http://maven.aliyun.com/nexus/content/groups/public/com/google/protobuf/protoc/3.1.0/protoc-3.1.0.pom Downloaded from alimaven: http://maven.aliyun.com/nexus/content/groups/public/com/google/protobuf/protoc/3.1.0/protoc-3.1.0.pom (4.5 kB at 4.3 kB/s) Downloading from alimaven: http://maven.aliyun.com/nexus/content/groups/public/com/google/protobuf/protoc/3.1.0/protoc-3.1.0-osx-x86_64.exe Downloaded from alimaven: http://maven.aliyun.com/nexus/content/groups/public/com/google/protobuf/protoc/3.1.0/protoc-3.1.0-osx-x86_64.exe (4.9 MB at 727 kB/s) [INFO] Compiling 1 proto file(s) to /Users/dugang/dugang/my/hellocode/demo/maven-proto-demo/target/generated-sources/protobuf/java 注意会自动下载对应的 protoc 编译器 protoc-3.1.0-osx-x86_64.exe 生成 java 文件 target/generated-sources/protobuf/java/dyyx/PersonProto.java target/generated-sources/protobuf/java 设置为源码目录 目录右键 Mark Directory As / Sources Root 建议把生成的java文件直接复制到 src 目录里
完整例子代码 https://gitee.com/dyyx/hellocode/tree/master/demo/maven-proto-demo
idea设置源码目录 protobuf 简介 及 java实例

上一篇     下一篇
arthas 查看 SQL

windows10 git log 中文显示问题

protoc 和 protobuf-java 版本不一致问题

spring data JPA

MybatisPlus简介

MybatisPlus QueryWrapper LambdaQueryWrapper LambdaQueryChainWrapper