Skip to content

fix: keep the published Kotlin metadata readable by Kotlin 2.2 consumers - #3468

Open
Inf1mum wants to merge 1 commit into
springdoc:mainfrom
Inf1mum:fix/kotlin-api-version-compatibility
Open

Inf1mum wants to merge 1 commit into
springdoc:mainfrom
Inf1mum:fix/kotlin-api-version-compatibility

Conversation

@Inf1mum

@Inf1mum Inf1mum commented Dec 4, 2026

Copy link
Copy Markdown

Fixes #3458.

What happened

Release 3.2.0 was built against spring-boot-starter-parent 4.1.2 (Kotlin 2.2); 3.2.1 moved the parent to 4.2.0, whose managed Kotlin compiler is 2.4. The Kotlin compiler writes the metadata level into the published jar, so the 3.2.1 springdoc-openapi-starter-common jar advertises Kotlin metadata 2.4.0 and any consumer compiling with Kotlin 2.2 (Spring Boot 4.0/4.1 apps) fails with:

META-INF/springdoc-openapi-starter-common.kotlin_module Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 2.4.0, expected version is 2.2.0.

What changed

springdoc-openapi-starter-common/pom.xml only — apiVersion 2.2 and languageVersion 2.2 on the module's kotlin-maven-plugin. That pins the emitted Kotlin metadata to level 2.2.0 (what 3.2.0 already shipped) while the compiler itself keeps coming from the Spring Boot version managed in the build. Nothing else changes: same module, same code, no dependency or source change. Modules without published Kotlin sources are untouched.

One note on the fix: apiVersion alone (which is what the issue suggested first) reaches the compiler but does not lower the emitted metadata version on Kotlin 2.4 — verified via the effective POM plus javap on the rebuilt classes (@kotlin.Metadata still mv=[2,4,0]). The metadata level follows languageVersion, so both are pinned together; apiVersion 2.2 additionally keeps the sources away from stdlib APIs newer than 2.2, which matters for real 2.2 consumers.

Verification (RED → GREEN)

Consumer probe: a minimal Maven project with the Kotlin 2.2.20 toolchain and springdoc-openapi-starter-common as the only jar on the classpath carrying newer-than-2.2 Kotlin metadata (transitive Kotlin/Jackson-module deps excluded), compiling one trivial Kotlin file.

RED — jar built from current main (3.2.2-SNAPSHOT, no fix):

[ERROR] .../springdoc-openapi-starter-common-3.2.2-SNAPSHOT.jar!/META-INF/springdoc-openapi-starter-common.kotlin_module Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 2.4.0, expected version is 2.2.0.
[INFO] BUILD FAILURE

Artifacts: classes in the unfixed jar carry @kotlin.Metadata(mv=[2,4,0]).

GREEN — jar rebuilt with this change:

[INFO] BUILD SUCCESS

Artifacts: @kotlin.Metadata now mv=[2,2,0]; the consumer compile succeeds with the 2.2.20 toolchain.

No regression: ./mvnw -pl springdoc-openapi-starter-common test — 81 tests run, 0 failures, 0 errors (includes the module's Kotlin tests SpringDocKotlinxSerializationConfigurationTest and KotlinxSerializationRequiredPropertyCustomizerTest, which compile fine under the pinned language level).

Scope guard

  • No runtime behavior of the generated OpenAPI descriptions changes — only the Kotlin metadata level of published artifacts.
  • No dependency version changes — the Kotlin compiler still comes from the managed Spring Boot parent (4.2.0).
  • Other modules (springdoc-openapi-starter-common-mcp, starters, tests) are not touched.

Since 3.2.1 the build inherits Spring Boot 4.2 and its Kotlin 2.4
compiler, so the published springdoc-openapi-starter-common jar
advertises Kotlin metadata 2.4.0 and breaks compilation of any Kotlin
2.2 consumer (Spring Boot 4.0/4.1 apps) with 'Module was compiled with
an incompatible version of Kotlin'.

Pin apiVersion and languageVersion to 2.2 on the kotlin-maven-plugin of
the only published module with Kotlin sources, so the emitted metadata
stays at level 2.2.0 (as in 3.2.0) while the compiler itself continues
to come from the managed Spring Boot version.

Fixes springdoc#3458

Signed-off-by: Vadim Lazuk <vadimlazuk5@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spring Boot 4.2 upgrade breaks Kotlin compatibility

1 participant