未解决的参考:protoc-使用Gradle+ProtocolBuffers时
我有一个使用 Kotlin DSL 的 gradle 项目
build.gradle.kts
plugins {
kotlin("jvm") version "1.4.21"
id("com.google.protobuf") version "0.8.10"
}
group = "schema"
version = "0.0.1-SNAPSHOT"
repositories {
mavenCentral()
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.0.0"
}
}
模式.proto
syntax = "proto3";
package schema;
message Message {
string content = 1;
string date_time = 2;
}
和项目结构
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。我究竟做错了什么?
回答
我认为这是因为您在 protobuf gradle 插件中引用了单个任务。尝试导入整个包以根据需要使用类型安全的访问器。
import com.google.protobuf.gradle.*
THE END
二维码