google / protobuf-gradle-plugin

Protobuf Plugin for Gradle
Other
1.76k stars 274 forks source link

Generated code not found by Kotlin compiler when upgrading form 0.9.1 #724

Closed andrewparmet closed 1 year ago

andrewparmet commented 1 year ago

I tried upgrading this plugin from 0.9.1 to anything later. 0.9.2 fails with https://github.com/google/protobuf-gradle-plugin/issues/656. 0.9.3 and 0.9.4 both fail because of unresolved references to generated code:

> Task :protokt-codegen:compileKotlin FAILED
e: file:///Users/andrew.parmet/.../protokt/protokt-codegen/src/main/kotlin/protokt/v1/codegen/Main.kt:23:29 Unresolved reference: v1
e: file:///Users/andrew.parmet/.../protokt/protokt-codegen/src/main/kotlin/protokt/v1/codegen/Main.kt:96:21 Unresolved reference: ProtoktProto

... and more

What's weird is that the code is being generated and IntelliJ sees it and marks the directory as a generated sources root!

Screenshot 2023-07-17 at 12 14 49 AM

The project and its last working commit is https://github.com/andrewparmet/protokt/commit/d960163ce7c2014e03ed52e1c889f446258cd026.

The failure occurs in the first subproject that does Protobuf codegen, protokt-codegen.

To repro, update: https://github.com/andrewparmet/protokt/blob/d960163ce7c2014e03ed52e1c889f446258cd026/gradle/libs.versions.toml#L24

It's a complex project overall but the protokt-codegen subproject is simple from the Protobuf codegen perspective:

sourceSets {
    main {
        proto {
            srcDir("../extensions/protokt-extensions-lite/src/main/proto")
        }
    }
}

I've also tried reworking this to pull the proto files directly into src/main/proto instead of where they are today to no avail.

I'm aware of the internal changes to this plugin across these versions but not sure what might cause a failure quite like this. Any tips?

Thanks!

andrewparmet commented 1 year ago

Turns out I had a wonky source set config and was accidentally excluding the generated files.