marcoferrer / kroto-plus

gRPC Kotlin Coroutines, Protobuf DSL, Scripting for Protoc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot configure krotoPlus protoc task via Kotlin gradle script, fallsback to asciipb file

Strum355 opened this issue · comments

Kroto Plus version: 0.6.1
com.google.protobuf version: 0.8.15


When trying to adapt the example krotoPlusConfig.gradle to Kotlin Gradle script, I havent been successful. My only success has been with the config defined in a json file (and presumably will also work for asciipb etc).

For the first code snippet, I get the following exception:

Execution failed for task ':semanticdb-kotlin:generateProto'.
> protoc: stdout: . stderr: Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
  Caused by: java.lang.IllegalStateException: Config file does not exist. '/home/noah/Sourcegraph/lsif-kotlin/semanticdb-kotlin/build/kroto/config/main.asciipb'
        at com.github.marcoferrer.krotoplus.generators.GeneratorContextKt.getConfigFile(GeneratorContext.kt:74)
        at com.github.marcoferrer.krotoplus.generators.GeneratorContextKt.getCompilerConfig(GeneratorContext.kt:53)
        at com.github.marcoferrer.krotoplus.generators.GeneratorContext.<init>(GeneratorContext.kt:36)
        at com.github.marcoferrer.krotoplus.generators.GeneratorKt.initializeContext(Generator.kt:86)
        at com.github.marcoferrer.krotoplus.generators.GeneratorKt.initializeContext$default(Generator.kt:75)
        at com.github.marcoferrer.krotoplus.KrotoPlusProtoCMain.main(KrotoPlusProtoCMain.kt:32)
        ... 8 more
  --kroto_out: protoc-gen-kroto: Plugin failed with status code 1.
// ...

krotoPlus {
    config {
        register("main") {
            builder.protoBuilders {
                useDslMarkers = true
                unwrapBuilders = true
            }
        }
    }
}

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

    generatedFilesBaseDir = sourceSets.main.get().kotlin.sourceDirectories.asPath.split(":")[0].removeSuffix("main/kotlin")

    plugins {
        id("kroto") { artifact = "com.github.marcoferrer.krotoplus:protoc-gen-kroto-plus:0.6.1" }
    }

    generateProtoTasks {
        val krotoConfig = file("${projectDir}/krotoconfig.json")
        all().forEach { task ->
            task.inputs.files(krotoConfig)

            task.plugins {
                id("kroto") {
                    outputSubDir = "java"
                    option(krotoPlus.config["main"].asOption())
					//option("ConfigPath=${krotoConfig}")
                }
            }
        }
    }
}

With the following diff, I get com.github.marcoferrer.krotoplus.config.CompilerConfig$Builder cannot be cast to com.github.marcoferrer.krotoplus.gradle.compiler.CompilerConfigWrapper:

34c34
<         register("main") {
---
>         id("main") {