1 maven插件方式
1.1 pom文件
<os-maven-plugin.version>1.6.2</os-maven-plugin.version>
<protobuf-maven-plugin.version>0.6.1</protobuf-maven-plugin.version>
<com.google.protobuf.protoc.version>3.12.0</com.google.protobuf.protoc.version>
<protoc-gen-grpc-java.plugin.version>1.32.1</protoc-gen-grpc-java.plugin.version>
<grpc.version>1.32.1</grpc.version>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!--获取操作系统信息
os.detected.name 操作系统名称 linux/windows/osx等
os.detected.arch 操作系统架构 x86_32/x86_64/arm_32/aarch_64等
os.detected.bitness 操作系统位数 32/64
os.detected.version.* 操作系统版本相关
os.detected.classifier 操作系统名称和架构 ${os.detected.name}-${os.detected.arch}
-->
<plugin>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>${os-maven-plugin.version}</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>detect</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>${protobuf-maven-plugin.version}</version>
<configuration>
<protocArtifact>
com.google.protobuf:protoc:${com.google.protobuf.protoc.version}:exe:${os.detected.classifier}
</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>
io.grpc:protoc-gen-grpc-java:${protoc-gen-grpc-java.plugin.version}:exe:${os.detected.classifier}
</pluginArtifact>
</configuration>
<executions>
<execution>
<id>grpc-build</id>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
2. 使用样例
2.1 proto文件
syntax = "proto3";
package demo.sw;
message DemoProto {
string service = 1;
// Service version in browser is the Instance concept in the backend.
string serviceVersion = 2;
// Perf data time, set by the backend side.
int64 time = 3;
// Page path in browser is the endpoint concept in the backend
// Page path in the browser, mostly it is URI, without parameter
string pagePath = 4;
// Unit of all time related field should be `ms`.
int32 redirectTime = 5;
// DNS query time
int32 dnsTime = 6;
// Time to first Byte
int32 ttfbTime = 7;
// TCP connection time
int32 tcpTime = 8;
// Content transfer time
int32 transTime = 9;
// Dom parsing time
int32 domAnalysisTime = 10;
// First paint time or blank screen time
int32 fptTime = 11;
// Dom ready time
int32 domReadyTime = 12;
// Page full load time
int32 loadPageTime = 13;
// Synchronous load resources in the page
int32 resTime = 14;
// Only valid for HTTPS
int32 sslTime = 15;
// Time to interact
int32 ttlTime = 16;
// First pack time
int32 firstPackTime = 17;
// First Meaningful Paint
int32 fmpTime = 18;
}
2.2 idea编译
2.3 将生成文件目录加入Sources Root