gpt4 book ai didi

gradle - gRPC 梯度 :generateProto fails with directory not found when importing other proto definitions

转载 作者:行者123 更新时间:2023-12-03 05:56:09 25 4
gpt4 key购买 nike

我正在尝试将一些 protobuf 定义编译为 gradle 任务,但是在没有源生成的情况下出现以下错误:

* What went wrong:
Execution failed for task ':generateProto'.
> protoc: stdout: . stderr: /Users/ash/IdeaProjects/kotlin/grpc/build/extracted-protos/main: warning: directory does not exist.
service-definitions.proto:10:17: "Empty" is not defined.
service-definitions.proto:10:33: "Empty" is not defined.
service-definitions.proto:15:17: "SimpleRequest" is not defined.
service-definitions.proto:15:41: "SimpleResponse" is not defined.
service-definitions.proto:21:27: "StreamingOutputCallRequest" is not defined.
service-definitions.proto:21:71: "StreamingOutputCallResponse" is not defined.
service-definitions.proto:27:33: "StreamingInputCallRequest" is not defined.
service-definitions.proto:27:69: "StreamingInputCallResponse" is not defined.
service-definitions.proto:34:29: "StreamingOutputCallRequest" is not defined.
service-definitions.proto:34:73: "StreamingOutputCallResponse" is not defined.
service-definitions.proto: warning: Import empty.proto but not used.
service-definitions.proto: warning: Import messages.proto but not used.

这仅在我尝试编译导入其他定义的定义时发生。如果我删除 service-definitions.proto定义,其他编译并生成源代码。

protobuf 定义可从 vertx-grpc examples 获得。我有他们在 $projectDir/src/main/proto .我没有更改它们的默认构建位置,所以源被生成到 $projectDir/build/generated/source/proto .而不是 extracted-protos目录,但是,我有 extracted-include-protos (可能解释了找不到目录的错误)。

这是我的 gradle.build文件,应该有用吗。请注意,gRPC 插件使用 Vert.x 工件,而不是来自 io.grpc.. 的版本。 (它实际上只是它顶部的一个包装器)。我尝试将 Vert.x 版本换成 io.grpc版本并得到相同的错误。
group 'grpc'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.1.3'

repositories {
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.1"
}
}

apply plugin: 'kotlin'
apply plugin: "java"
apply plugin: "com.google.protobuf"
apply plugin: "idea"

protobuf {
//generatedFilesBaseDir = "$projectDir/build/generated/source/proto"
protoc {
artifact = "com.google.protobuf:protoc:3.3.0"
}
plugins {
grpc {
artifact = "io.vertx:protoc-gen-grpc-java:1.3.0"
}
}
generateProtoTasks {
all().each { task ->
task.plugins {
grpc {}
}
}
}
}

clean {
delete protobuf.generatedFilesBaseDir
}

idea {
module {
sourceDirs += file("${protobuf.generatedFilesBaseDir}/main/java")
sourceDirs += file("${protobuf.generatedFilesBaseDir}/main/grpc")
}
}

sourceSets {
main {
java {
srcDirs += "${protobuf.generatedFilesBaseDir}/main/java"
srcDirs += "${protobuf.generatedFilesBaseDir}/main/grpc"
}
}
}

repositories {
jcenter()
}

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
compile "io.vertx:vertx-core:3.4.2"
compile "io.vertx:vertx-web:3.4.2"
compile "io.vertx:vertx-grpc:3.4.2"
}

compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
apiVersion = "1.1"
languageVersion = "1.1"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
apiVersion = "1.1"
languageVersion = "1.1"
}
}

我没有更改任何设置,为什么 (a) 在错误的位置查找提取的文件,以及 (b) 在导入时完全查找提取的文件,因为必要的定义都在 src/main/proto 中目录?

最佳答案

好的,经过多次挠头,线索在错误消息的最后两行:

service-definitions.proto: warning: Import empty.proto but not used.
service-definitions.proto: warning: Import messages.proto but not used.

在我的原型(prototype)定义中,我指定了 messagesemptymessages包,但在导入定义中使用时没有限定类型,在 services 中包裹。唉,一个简单的改变,它的工作原理:
package services;
service EmptyPingPongService {
// One empty request followed by one empty response.
rpc EmptyCall(Empty) returns (Empty);
}

变成:
package services;    
service EmptyPingPongService {
// One empty request followed by one empty response.
rpc EmptyCall(messages.Empty) returns (messages.Empty);
}

关于gradle - gRPC 梯度 :generateProto fails with directory not found when importing other proto definitions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44808520/

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