Skip to content

Well-known types are not mapped #291

@milux

Description

@milux

The documentation of this project states:

If the google.protobuf package is referenced, it is assumed to be a well-known type and is changed to reference pbandk.wkt.

However, this is not what we observe.
When I don't pass any extra options to the Gradle plugin, the result looks like this:

Image

This causes class name clashes in the resulting Java application.

When I supply a mapping via option("kotlin_package_mapping=google.protobuf->pbandk.wkt"), it still generates JavaFeatures:

Image

Can anybody explain me why this happens?
If I understand the documentation right, any well-known stuff from google.protobuf should come from the pbandk runtime and not result in generated code in the first place, right?

For reference:
We talk about a KMP (Kotlin Multi Platform) project and the protobuf config looks like this:

protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:${libs.versions.protobuf.get()}"
    }
    plugins {
        id("pbandk") {
            artifact = "pro.streem.pbandk:protoc-gen-pbandk-jvm:${libs.versions.pbandk.get()}:jvm8@jar"
        }
    }
    generateProtoTasks {
        ofSourceSet("main").forEach { task ->
            task.builtins {
                remove("java")
            }
            task.plugins {
                id("pbandk") {
                    option("kotlin_package_mapping=google.protobuf->pbandk.wkt")
                    // Publish the code generated by pbandk as part of the `:protobuf-codegen` project's
                    // `commonMain` source set. This allows other Kotlin Multiplatform subprojects to consume the
                    // pbandk-generated Kotlin code using a regular Gradle project dependency.
                    val outputDir = task.getOutputDir(this)
                    project.kotlin.sourceSets.commonMain.configure {
                        // `builtBy` ensures that Gradle will automatically run the `generateProto` task before trying
                        // to compile the generated Kotlin code
                        kotlin.srcDir(project.files(outputDir).builtBy(task))
                    }
                }
            }
        }
    }
}

Any hints or ideas how to fix this appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions