在 jetpack 数据存储中,您必须设置 gradle 插件任务以从文件中生成类.proto
:
// build.gradle
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.10.0"
}
// Generates the java Protobuf-lite code for the Protobufs in this project. See
// https://github.com/google/protobuf-gradle-plugin#customizing-protobuf-compilation
// for more information.
generateProtoTasks {
all().each { task ->
task.builtins {
java {
option 'lite'
}
}
}
}
}
在我的项目中,我将Kotlin dsl用于我的 gradle 项目。尝试将其转换为 kotlin dsl 后,option
属性未知,我找不到它可以替代 kotlin kts
// build.gradle.kts
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.10.0"
}
generateProtoTasks {
all().forEach { task ->
task.builtins {
java {
option = "lite" // ** option is unknown **
}
}
}
}
}