KTS project practise
- Gradle
- Ktlint
I speed more than two hours to add protobuf dependence into my project, because the reference is so limited, I mired down in mud. Finally, I make my project with protobuf work.
Here are some key steps:
-
Add protobuf gradle in classpath
buildscript { repositories { maven("https://plugins.gradle.org/m2/") } dependencies { classpath(Gradle.Dependency.PROTOBUF_GRADLE) } }
-
Import protobuf into your app.gradle to use
protobuf
import com.google.protobuf.gradle.*
-
Add protobuf plugin
plugins { id(Gradle.Plugins.PROTOBUF) }
-
Add protobuf-java dependence
implementation("com.google.protobuf:protobuf-java:${Deps.Protobuf.PROTO_VERSION}")
-
Config protobuf with grpc and javalite to avoid
package com.google.protobuf does not exist
protobuf { protoc { artifact = Deps.Protobuf.PROTO_C } plugins { id("grpc") { artifact = Deps.Protobuf.Plugin.GRPC } id("javalite") { artifact = Deps.Protobuf.Plugin.JAVALITE } } generateProtoTasks { all().forEach { it.plugins { id("grpc") { option("lite") } id("javalite") } } } }
References: