Skip to content

Register generated Kotlin sources via the Kotlin Gradle plugin API#186

Merged
alexander-yevsyukov merged 9 commits into
masterfrom
register-generated-kotlin-src
Jun 29, 2026
Merged

Register generated Kotlin sources via the Kotlin Gradle plugin API#186
alexander-yevsyukov merged 9 commits into
masterfrom
register-generated-kotlin-src

Conversation

@alexander-yevsyukov

Copy link
Copy Markdown
Contributor

What

Implements #185. GenerateProtoTask.configureSourceSetDirs() now registers the
copied, generated Kotlin sources through the Kotlin Gradle plugin's dedicated
KotlinSourceSet.generatedKotlin source directory set, instead of the plain
kotlin source set. The protoc output directories are still excluded from the
plain kotlin set, exactly as before.

Why

generatedKotlin (an @ExperimentalKotlinGradlePluginApi member, available in
KGP 2.3.21 which this repo uses) is the modern way to register generated Kotlin
sources. They are still compiled — allKotlinSources = kotlin + generatedKotlin,
which the Kotlin compile task consumes — but build tooling and IDEs can tell them
apart from hand-written code. This repo already reads generatedKotlin separately
in its Kover coverage configuration.

How

  • GeneratedSourcePlugin.kt: resolve the matching KotlinSourceSet (via the
    non-deprecated KotlinBaseExtension) and register the copied directory under its
    generatedKotlin. A single source-set lookup drives both the exclusion and the
    registration — the Gradle source set's kotlin extension is the same object as
    KotlinSourceSet.kotlin — gated on that extension's presence to preserve the
    original timing relative to the Protobuf plugin.

Tests

No existing spec applied the Kotlin plugin, so the Kotlin path was uncovered. Added
a TestKit spec in GeneratedSourcePluginSpec that applies the Kotlin JVM +
Protobuf + this plugin and asserts that generated/main/kotlin is registered under
generatedKotlin, is absent from the plain kotlin set, and that the .kt is
copied. Because this plugin references the KGP API as compileOnly, the spec puts
the Kotlin Gradle plugin on the plugin-under-test classpath so the plugin and KGP
share a classloader (otherwise TestKit isolates them and KotlinBaseExtension
fails to resolve at runtime).

Versioning

Bumps 2.0.0-SNAPSHOT.402.403. The change is @Internal and non-breaking, so
a single snapshot increment.

Notes for reviewers

  • Reviewed locally by the kotlin-engineer and spine-code-review agents; both
    approved, and their feedback (single source-set lookup; import the task type) is
    folded in.
  • The branch also carries unrelated maintenance commits made directly on it
    (CI/config sync, IDEA settings, a dependency-report refresh).

🤖 Generated with Claude Code

alexander-yevsyukov and others added 7 commits June 29, 2026 17:35
Register the copied generated Kotlin directory through
`KotlinSourceSet.generatedKotlin` instead of the plain `kotlin` source set,
so that build tooling and IDEs can tell generated code apart from
hand-written sources. The protoc output dirs are still excluded from the
plain `kotlin` set, as before.

Add a TestKit spec covering the Kotlin path, which previously had no
coverage. It applies the Kotlin Gradle plugin from the plugin-under-test
classpath so the plugin and KGP share a classloader and the plugin can
resolve the Kotlin Gradle plugin API at runtime.

Closes #185.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Address code-review feedback. Drive both the protoc-output exclusion and
the `generatedKotlin` registration from a single `KotlinSourceSet` lookup
instead of two independent ones — the Gradle source set's `kotlin`
extension is the same object as `KotlinSourceSet.kotlin`, so this removes
the chance of the two views disagreeing while preserving the timing gate
on the extension's presence.

Also import `PluginUnderTestMetadata` in `build.gradle.kts` rather than
referencing it by its fully-qualified name inline.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 426f87c5dc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 44.44444% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.73%. Comparing base (bd9ea3a) to head (1a3bbd4).

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #186      +/-   ##
============================================
+ Coverage     90.45%   90.73%   +0.27%     
  Complexity      554      554              
============================================
  Files           122      122              
  Lines          2243     2246       +3     
  Branches        311      313       +2     
============================================
+ Hits           2029     2038       +9     
+ Misses           93       86       -7     
- Partials        121      122       +1     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements issue #185 by updating the Protobuf generated-sources wiring for Kotlin so that copied generated Kotlin sources are registered via the Kotlin Gradle plugin’s dedicated KotlinSourceSet.generatedKotlin directory set (while still excluding protoc output directories from the plain kotlin set). It also includes several additional build/publishing guard and dependency-maintenance updates carried on the same branch.

Changes:

  • Register copied generated Kotlin sources under generatedKotlin (instead of kotlin) and add a Gradle TestKit spec covering Kotlin + Protobuf + this plugin.
  • Extend version-guard/publishing infrastructure in buildSrc (base-branch comparison, Maven metadata parsing, version comparator, and task wiring).
  • Update snapshot versions and regenerate dependency reports / dependency constants.

Reviewed changes

Copilot reviewed 42 out of 43 changed files in this pull request and generated no comments.

Show a summary per file
File Description
version.gradle.kts Bumps publishing snapshot version to 2.0.0-SNAPSHOT.403.
protobuf-setup-plugins/src/test/kotlin/io/spine/tools/protobuf/gradle/plugin/GeneratedSourcePluginSpec.kt Adds TestKit coverage asserting generatedKotlin registration and exclusion from plain kotlin.
protobuf-setup-plugins/src/main/kotlin/io/spine/tools/protobuf/gradle/plugin/GeneratedSourcePlugin.kt Switches Kotlin generated dir registration to KotlinSourceSet.generatedKotlin and adds Kotlin source set lookup.
protobuf-setup-plugins/build.gradle.kts Adds Kotlin Gradle plugin to plugin-under-test classpath for TestKit isolation.
docs/dependencies/pom.xml Updates documented versions to the new snapshot and refreshed dependency versions.
docs/dependencies/dependencies.md Regenerates dependency report for the new snapshot (includes updated generation timestamp).
buildSrc/src/test/kotlin/io/spine/gradle/VersionGradleFileSpec.kt Adds unit tests for parsing version.gradle.kts publishing version declarations.
buildSrc/src/test/kotlin/io/spine/gradle/VersionComparatorSpec.kt Adds tests for semantic-ish version comparison logic.
buildSrc/src/test/kotlin/io/spine/gradle/publish/MavenMetadataSpec.kt Adds a Jackson XML round-trip test ensuring Maven metadata deserialization preserves versions.
buildSrc/src/test/kotlin/io/spine/gradle/publish/IncrementGuardTest.kt Expands IncrementGuard tests (CI/local publish scenarios, task wiring).
buildSrc/src/main/kotlin/kmp-module.gradle.kts Skips forced-resolution logic for Dokka configurations.
buildSrc/src/main/kotlin/jvm-module.gradle.kts Skips forced-resolution logic for Dokka configurations.
buildSrc/src/main/kotlin/io/spine/gradle/VersionGradleFile.kt Introduces parser/reader for version.gradle.kts, including base-branch reading via git show.
buildSrc/src/main/kotlin/io/spine/gradle/VersionComparator.kt Introduces comparator for “newest version” selection and base-branch increment checks.
buildSrc/src/main/kotlin/io/spine/gradle/report/pom/DependencyWriter.kt Uses VersionComparator to pick newest duplicate dependency versions deterministically.
buildSrc/src/main/kotlin/io/spine/gradle/publish/MavenMetadata.kt Extracts Maven metadata XML model + fetch/parse helper.
buildSrc/src/main/kotlin/io/spine/gradle/publish/IncrementGuard.kt Reworks checkVersionIncrement execution conditions and wires it before publishToMavenLocal.
buildSrc/src/main/kotlin/io/spine/gradle/publish/CheckVersionIncrement.kt Adds base-branch increment comparison and reuses extracted Maven metadata + version parsing/comparison.
buildSrc/src/main/kotlin/io/spine/gradle/kotlin/KotlinConfig.kt Refactors compiler opt-ins; scopes ExperimentalPathApi opt-in to JVM compilations only.
buildSrc/src/main/kotlin/io/spine/dependency/test/Testcontainers.kt Improves documentation and clarifies provided Testcontainers modules.
buildSrc/src/main/kotlin/io/spine/dependency/storage/QueryDsl.kt Adds QueryDSL dependency definition.
buildSrc/src/main/kotlin/io/spine/dependency/storage/PostgreSql.kt Adds PostgreSQL JDBC driver dependency definition.
buildSrc/src/main/kotlin/io/spine/dependency/storage/MySql.kt Adds MySQL Connector/J dependency definition.
buildSrc/src/main/kotlin/io/spine/dependency/storage/HsqlDb.kt Adds HSQLDB dependency definition.
buildSrc/src/main/kotlin/io/spine/dependency/storage/Hikari.kt Adds HikariCP dependency definition.
buildSrc/src/main/kotlin/io/spine/dependency/storage/H2.kt Adds H2 dependency definition.
buildSrc/src/main/kotlin/io/spine/dependency/local/ToolBase.kt Updates ToolBase dependency snapshot version constants.
buildSrc/src/main/kotlin/io/spine/dependency/local/Logging.kt Updates Spine Logging snapshot version constant.
buildSrc/src/main/kotlin/io/spine/dependency/local/CoreJvmCompiler.kt Updates Core JVM Compiler snapshot version constants.
buildSrc/src/main/kotlin/io/spine/dependency/local/CoreJvm.kt Updates Spine Core JVM snapshot version constant.
buildSrc/src/main/kotlin/io/spine/dependency/local/Compiler.kt Updates fallback compiler snapshot versions.
buildSrc/src/main/kotlin/io/spine/dependency/local/Base.kt Updates Spine Base snapshot version constants.
buildSrc/src/main/kotlin/io/spine/dependency/Dependency.kt Adds Configuration.isDokka helper to avoid forcing versions on Dokka configs.
buildSrc/src/main/kotlin/io/spine/dependency/boms/BomsPlugin.kt Excludes Dokka configurations from BOM-related forcing logic.
buildSrc/src/main/kotlin/dokka-setup.gradle.kts Disables Dokka Javadoc publication task for KMP modules.
buildSrc/src/main/kotlin/DependencyResolution.kt Skips forced-resolution logic for Dokka configurations.
.idea/kotlinc.xml Config-managed/IDE settings update (not reviewed).
.github/workflows/revalidate-versions.yml Config-managed workflow addition (not reviewed).
.github/workflows/publish.yml Config-managed workflow update (not reviewed).
.github/workflows/increment-guard.yml Config-managed workflow update (not reviewed).
.github/workflows/build-on-ubuntu.yml Config-managed workflow update (not reviewed).
.claude/settings.json Config-managed tool settings update (not reviewed).
Files not reviewed (1)
  • .idea/kotlinc.xml: Generated file

alexander-yevsyukov and others added 2 commits June 29, 2026 19:15
…vention

The `module` convention registered `generated/<sourceSet>/kotlin` in the plain
`kotlin` source set, so the `generatedKotlin` registration added for #185 had no
visible effect in modules that use the convention (tool-base, classic-codegen):
the directory stayed in both source sets, and IDEs/tooling still saw the copied
proto Kotlin as hand-written sources.

Stop registering generated Kotlin in the plain `kotlin` set here. The
`io.spine.generated-sources` plugin registers it under the Kotlin Gradle plugin's
dedicated `generatedKotlin` set, so the separation now takes effect. Java/gRPC
generated directories are still added as before.

Also normalize path separators in the TestKit spec so its source-set assertion
holds on Windows (`File` paths use backslashes there).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Replace the two inline `replace('\\', '/')` calls with a named private extension, removing the duplication.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@alexander-yevsyukov alexander-yevsyukov merged commit 1d3ac08 into master Jun 29, 2026
10 checks passed
@alexander-yevsyukov alexander-yevsyukov deleted the register-generated-kotlin-src branch June 29, 2026 18:51
@github-project-automation github-project-automation Bot moved this from 🏗 In progress to ✅ Done in v2.0 Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants