gpt4 book ai didi

java - 协议(protocol)-jar-maven-插件 : Not generating grpc service stubs

转载 作者:搜寻专家 更新时间:2023-11-01 03:31:36 26 4
gpt4 key购买 nike

我添加了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 服务 stub ,只将“消息”转换为 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

我有一个简单的原型(prototype)文件定义为

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 服务 stub 丢失。我是 Maven 的新手,我是不是错过了什么。

最佳答案

使用 Maven 阶段 ... https://maven.apache.org/ref/3.5.2/maven-core/lifecycles.html

mvn generate-sources 将生成您的 GreeterRpc

关于java - 协议(protocol)-jar-maven-插件 : Not generating grpc service stubs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51237952/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com