Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kotlin 未解析引用:protoc-使用Gradle+协议缓冲区时_Kotlin_Gradle_Protocol Buffers - Fatal编程技术网

Kotlin 未解析引用:protoc-使用Gradle+协议缓冲区时

Kotlin 未解析引用:protoc-使用Gradle+协议缓冲区时,kotlin,gradle,protocol-buffers,Kotlin,Gradle,Protocol Buffers,我有一个使用Kotlin DSL的gradle项目 build.gradle.kts schema.proto 和项目结构 schema -src/main/proto/schema.proto -build.gradle.kts 无论何时运行gradle build,我都会收到错误: FAILURE: Build failed with an exception. * Where: Build file '/Users/x/schema/build.gradle.kts' line: 13

我有一个使用Kotlin DSL的gradle项目

build.gradle.kts

schema.proto

和项目结构

schema
-src/main/proto/schema.proto
-build.gradle.kts
无论何时运行gradle build,我都会收到错误:

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/x/schema/build.gradle.kts' line: 13

* What went wrong:
Script compilation errors:

   Line 15:      protoc {
        ^ Unresolved reference: protoc

   Line 16:              artifact = "com.google.protobuf:protoc:3.0.0"
         ^ Unresolved reference: artifact

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 8s

我所做的唯一不同于各种教程的事情是使用Gradle Kotlin DSL。我做错了什么?

无论出于什么原因,这都有效

import com.google.protobuf.gradle.protoc

protobuf {
    protobuf.protoc {
        artifact = "com.google.protobuf:protoc:3.0.0"
    }
}

无论出于何种原因,必须两次指定protobuf mind似乎有点难看

import com.google.protobuf.gradle.protoc

protobuf {
    protobuf.protoc {
        artifact = "com.google.protobuf:protoc:3.0.0"
    }
}

两次指定protobuf似乎有点难看,我想这是因为你在protobuf-gradle插件中引用了一个任务。尝试导入整个包,以便根据需要使用类型安全访问器

import com.google.protobuf.gradle.*

我认为这是因为您正在protobuf gradle插件中引用单个任务。尝试导入整个包,以便根据需要使用类型安全访问器

import com.google.protobuf.gradle.*