Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please update the Datastore with Protobuf codelab to support Gradle Kotlin DSL / Kotlin code generation #59

Open
danielesegato opened this issue Nov 11, 2022 · 2 comments

Comments

@danielesegato
Copy link

danielesegato commented Nov 11, 2022

Hi,

It took me some hours to figure out how to set it up correctly, I think the codelab should mention it:

import com.google.protobuf.gradle.id

plugins {
  // ...
  id("com.google.protobuf") // version 0.9.1
}

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

    // 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 {
        // see https://github.com/google/protobuf-gradle-plugin/issues/518
        // see https://github.com/google/protobuf-gradle-plugin/issues/491
        
        // all() here because of android multi-variant
        all().forEach { task ->
            // this only works on version 3.8+ that has buildins for javalite / kotlin lite
            // with previous version the java build in is to be removed and a new plugin
            // need to be declared
            task.builtins {
                id("java") { // id is imported above
                    option("lite")
                }
                id("kotlin") {
                    option("lite")
                }
            }
        }
    }
}

depencencies {
  // ...
  implementaiton("com.google.protobuf:protobuf-javalite:3.21.9")
  implementaiton("com.google.protobuf:protobuf-kotlin-lite:3.21.9")
  // ....
}

this generate kotlin helpers for the proto and correctly works on gradle kotlin-dsl

the codelab only show how to configure for java and gradle groovy

@mariobat88
Copy link

I was struggling with that for so long. Thank you @danielesegato

@kanetik
Copy link

kanetik commented Oct 20, 2023

@danielesegato Wish I'd found this about 3 days ago! I finally got it to build the Kotlin DSL after FAR too much trial and error. However, what's weird now is that when I try to write a pref like so: userData { thingDateTime = timestamp } it doesn't seem to actually save the value. Do you happen to have working examples using the DSL? I'd love to see how you did it, if so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants