2

I'm having issue converting these gradle groovy code to kotlin dsl.

protobuf {
  protoc {
    artifact = 'com.google.protobuf:protoc:3.8.0'
  }
  generateProtoTasks {
    all().each { task ->
      task.builtins {
        java {
          option "lite"
        }
      }
    }
  }
}

Especially the option "lite" in java block.

Thanks.

Riajul
  • 1,140
  • 15
  • 20

1 Answers1

3

You can try this with Kotlin DSL.

build.gradle.kts

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

    generateProtoTasks {
        all().forEach {
            it.builtins {
                create("java") {
                    option("lite")
                }
            }
        }
    }
}
Dương Minh
  • 2,062
  • 1
  • 9
  • 21
  • 1
    `create("java")` might not work always, As in my case I'm using `getByName("java")`. Thanks. – Riajul Aug 26 '21 at 05:21
  • 2
    And also need to add these imports: `import com.google.protobuf.gradle.generateProtoTasks import com.google.protobuf.gradle.protobuf import com.google.protobuf.gradle.protoc` – Riajul Aug 26 '21 at 05:22
  • I've found that if you have to use `getByName("")` it means you've already created a task. Should be correct, that would use `create("")` and `getByName("")` depending on the case. As for import, I use ` import com.google.protobuf.gradle.*`. And I appreciate your comments. – Dương Minh Aug 26 '21 at 08:05