我有一个使用KotlinDSL的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"
}
}
schema.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
我做的唯一与各种教程不同的事情是使用GradleKotlinDSL。我做错了什么?
3条答案
按热度按时间isr3a4wc1#
我认为这是因为你在protobuf gradle插件中引用了一个单一的任务。尝试导入整个bundle以根据你的需要使用类型安全的访问器。
aemubtdh2#
不管是什么原因,这是可行的
必须指定
protobuf
两次似乎有点难看jgovgodb3#
如果你使用的是Kotlin,在你的应用级kts gradle中,你需要根据google/protobuf-gradle-plugin从
protobuf
gradleimport com.google.protobuf.gradle.*
导入所有内容。别忘了
您需要做的最后一项任务是将Protobuf类路径添加到您的项目级Gradle Kts中