Register generated Kotlin sources via the Kotlin Gradle plugin API#186
Conversation
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>
There was a problem hiding this comment.
💡 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 Report❌ Patch coverage is 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:
|
There was a problem hiding this comment.
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 ofkotlin) 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
…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>
What
Implements #185.
GenerateProtoTask.configureSourceSetDirs()now registers thecopied, generated Kotlin sources through the Kotlin Gradle plugin's dedicated
KotlinSourceSet.generatedKotlinsource directory set, instead of the plainkotlinsource set. The protoc output directories are still excluded from theplain
kotlinset, exactly as before.Why
generatedKotlin(an@ExperimentalKotlinGradlePluginApimember, available inKGP 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
generatedKotlinseparatelyin its Kover coverage configuration.
How
GeneratedSourcePlugin.kt: resolve the matchingKotlinSourceSet(via thenon-deprecated
KotlinBaseExtension) and register the copied directory under itsgeneratedKotlin. A single source-set lookup drives both the exclusion and theregistration — the Gradle source set's
kotlinextension is the same object asKotlinSourceSet.kotlin— gated on that extension's presence to preserve theoriginal 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
GeneratedSourcePluginSpecthat applies the Kotlin JVM +Protobuf + this plugin and asserts that
generated/main/kotlinis registered undergeneratedKotlin, is absent from the plainkotlinset, and that the.ktiscopied. Because this plugin references the KGP API as
compileOnly, the spec putsthe Kotlin Gradle plugin on the plugin-under-test classpath so the plugin and KGP
share a classloader (otherwise TestKit isolates them and
KotlinBaseExtensionfails to resolve at runtime).
Versioning
Bumps
2.0.0-SNAPSHOT.402→.403. The change is@Internaland non-breaking, soa single snapshot increment.
Notes for reviewers
kotlin-engineerandspine-code-reviewagents; bothapproved, and their feedback (single source-set lookup; import the task type) is
folded in.
(CI/
configsync, IDEA settings, a dependency-report refresh).🤖 Generated with Claude Code