protoc-jar-maven-plugin:不生成 grpc 服务存根
protoc-jar-maven-plugin: Not generating grpc service stubs
我添加了maven配置如下
<plugin>
<groupId>com.github.os72</groupId>
<artifactId>protoc-jar-maven-plugin</artifactId>
<version>3.5.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.0.0</protocArtifact>
<inputDirectories>
<include>src/main/protobuf</include>
</inputDirectories>
<outputTargets>
<outputTarget>
<type>java</type>
<outputDirectory>src/main/java</outputDirectory>
</outputTarget>
<outputTarget>
<type>grpc-java</type>
<outputDirectory>src/main/java</outputDirectory>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.0.1</pluginArtifact>
</outputTarget>
</outputTargets>
</configuration>
</execution>
</executions>
</plugin>
我正在通过 "mvn protoc-jar:run" 执行它,但是它跳过了 grpc 服务存根,仅将 "messages" 转换为 java 代码。
输出是
[INFO] Protoc version: 3.5.1
protoc-jar: protoc version: 3.5.1, detected platform: osx-x86_64 (mac os x/x86_64)
protoc-jar: embedded: bin/3.5.1/protoc-3.5.1-osx-x86_64.exe
protoc-jar: executing: [/var/folders/9y/w8qrc__9513dv57323sjdlmw0000gn/T/protocjar320569499467403052/bin/protoc.exe, --version]
libprotoc 3.5.1
[INFO] Protoc command: /var/folders/9y/w8qrc__9513dv57323sjdlmw0000gn/T/protocjar320569499467403052/bin/protoc.exe
[INFO] Input directories:
[INFO] /Users/dev/learn/proto-java/src/main/protobuf
[INFO] Output targets:
[INFO] java: /Users/dev/learn/proto-java/target/generated-sources (add: main, clean: false, plugin: null, outputOptions: null)
[INFO] Processing (java): helloworld.proto
protoc-jar: executing: [/var/folders/9y/w8qrc__9513dv57323sjdlmw0000gn/T/protocjar320569499467403052/bin/protoc.exe, -I/Users/dev/learn/proto-java/src/main/protobuf, --java_out=/Users/dev/learn/proto-java/target/generated-sources, /Users/dev/learn/proto-java/src/main/protobuf/helloworld.proto]
[INFO] Adding generated classes to classpath
我有一个简单的原型文件定义为
syntax = "proto3";
option java_multiple_files = true;
option java_package = "-.-.-.helloworld";
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW";
package helloworld;
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
rpc SayHelloAgain (HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}
我只输出生成为 HelloReply、HelloReplyOrBuilder、HelloRequest、HelloRequestOrBuilder、HelloWorldProto 的文件。 Greeter Grpc 服务存根丢失。我是 Maven 的新手,我是不是错过了什么。
使用 maven 阶段...https://maven.apache.org/ref/3.5.2/maven-core/lifecycles.html
mvn generate-sources
将生成您的 GreeterRpc
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.1</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.4.0:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<id>protobuf-generate</id>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
我添加了maven配置如下
<plugin>
<groupId>com.github.os72</groupId>
<artifactId>protoc-jar-maven-plugin</artifactId>
<version>3.5.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.0.0</protocArtifact>
<inputDirectories>
<include>src/main/protobuf</include>
</inputDirectories>
<outputTargets>
<outputTarget>
<type>java</type>
<outputDirectory>src/main/java</outputDirectory>
</outputTarget>
<outputTarget>
<type>grpc-java</type>
<outputDirectory>src/main/java</outputDirectory>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.0.1</pluginArtifact>
</outputTarget>
</outputTargets>
</configuration>
</execution>
</executions>
</plugin>
我正在通过 "mvn protoc-jar:run" 执行它,但是它跳过了 grpc 服务存根,仅将 "messages" 转换为 java 代码。
输出是
[INFO] Protoc version: 3.5.1
protoc-jar: protoc version: 3.5.1, detected platform: osx-x86_64 (mac os x/x86_64)
protoc-jar: embedded: bin/3.5.1/protoc-3.5.1-osx-x86_64.exe
protoc-jar: executing: [/var/folders/9y/w8qrc__9513dv57323sjdlmw0000gn/T/protocjar320569499467403052/bin/protoc.exe, --version]
libprotoc 3.5.1
[INFO] Protoc command: /var/folders/9y/w8qrc__9513dv57323sjdlmw0000gn/T/protocjar320569499467403052/bin/protoc.exe
[INFO] Input directories:
[INFO] /Users/dev/learn/proto-java/src/main/protobuf
[INFO] Output targets:
[INFO] java: /Users/dev/learn/proto-java/target/generated-sources (add: main, clean: false, plugin: null, outputOptions: null)
[INFO] Processing (java): helloworld.proto
protoc-jar: executing: [/var/folders/9y/w8qrc__9513dv57323sjdlmw0000gn/T/protocjar320569499467403052/bin/protoc.exe, -I/Users/dev/learn/proto-java/src/main/protobuf, --java_out=/Users/dev/learn/proto-java/target/generated-sources, /Users/dev/learn/proto-java/src/main/protobuf/helloworld.proto]
[INFO] Adding generated classes to classpath
我有一个简单的原型文件定义为
syntax = "proto3";
option java_multiple_files = true;
option java_package = "-.-.-.helloworld";
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW";
package helloworld;
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
rpc SayHelloAgain (HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}
我只输出生成为 HelloReply、HelloReplyOrBuilder、HelloRequest、HelloRequestOrBuilder、HelloWorldProto 的文件。 Greeter Grpc 服务存根丢失。我是 Maven 的新手,我是不是错过了什么。
使用 maven 阶段...https://maven.apache.org/ref/3.5.2/maven-core/lifecycles.html
mvn generate-sources
将生成您的 GreeterRpc
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.1</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.4.0:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<id>protobuf-generate</id>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>