Skip to content

Conversation

@ambushwork
Copy link
Member

Context

Prior to this PR, we use Kotlin 2.0.21 for the whole project, when compiling the kotlin22 source set, the compiler will throw the error saying:

Class 'org.jetbrains.kotlin.backend.common.extensions.FirIncompatiblePluginAPI' was compiled with an incompatible version of Kotlin. The actual metadata version is 2.2.0, but the compiler version 2.0.0 can read versions up to 2.1.

Then we have to add following argument to the compiler to let it pass:

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
    kotlinOptions {
        freeCompilerArgs += "-Xskip-metadata-version-check"
    }
}

What does this PR do?

To remove this, we need to upgrade Kotlin compiler version to 2.1.x.

Motivation

RUM-11262

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@codecov-commenter
Copy link

codecov-commenter commented Aug 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.78%. Comparing base (3dd9c5c) to head (c4f9f5b).

Additional details and impacted files
@@                       Coverage Diff                        @@
##             feature/kotlin-source-sets     #420      +/-   ##
================================================================
- Coverage                         76.06%   75.78%   -0.28%     
+ Complexity                          279      278       -1     
================================================================
  Files                                35       35              
  Lines                              1057     1057              
  Branches                            129      129              
================================================================
- Hits                                804      801       -3     
- Misses                              194      195       +1     
- Partials                             59       61       +2     

see 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ambushwork ambushwork force-pushed the yl/kcp/upgradle-kotlin-compiler-to-2-1-21 branch from 26fab16 to c4f9f5b Compare August 19, 2025 06:11
@ambushwork ambushwork changed the title RUM-11262: Upgrade Kotlin version to 2.1.21 to suppress Compiler version check error RUM-11262: Upgrade Kotlin Version to 2.1.21 to remove metadata check error Aug 19, 2025

// Dependencies used to configure the gradle plugins
implementation(embeddedKotlin("gradle-plugin"))
implementation(libs.kotlinPluginGradle)
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: we must switch to the designated version of plugin gradle (2.1.21), otherwise the version embedded in AGP is always 2.0.21

Copy link
Member

Choose a reason for hiding this comment

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

ideally we should just move away from buildSrc usage, because it leaks classpath

compileOnly(libs.androidToolsPluginGradle) // for auto-wiring into Android projects
compileOnly(libs.kotlinPluginGradle)
compileOnly(libs.kotlinCompilerEmbeddable)
compileOnly(libs.kotlinPluginGradle)
Copy link
Member Author

Choose a reason for hiding this comment

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

There are few classes (only used for auto instrumentation, such as CommandLineProcessor) existing both in kotlinPluginGradle and kotlinCompilerEmbeddable, the compiler will resolve it by the order defined here. (And also weird enough, this conflict happens only with kotlin 2.1.x version, neither in 2.0.x nor 2.2.x)

In this case I need to reverse the order so that compiler take always the one from kotlinCompilerEmbeddable when there are some duplications. May be we need to consider something safer, but this is the easiest fix that I can find for now.

@ambushwork ambushwork marked this pull request as ready for review August 19, 2025 06:13
@ambushwork ambushwork requested review from a team as code owners August 19, 2025 06:13

// Dependencies used to configure the gradle plugins
implementation(embeddedKotlin("gradle-plugin"))
implementation(libs.kotlinPluginGradle)
Copy link
Member

Choose a reason for hiding this comment

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

ideally we should just move away from buildSrc usage, because it leaks classpath

@ambushwork ambushwork merged commit dbaea7f into feature/kotlin-source-sets Aug 19, 2025
14 checks passed
@ambushwork ambushwork deleted the yl/kcp/upgradle-kotlin-compiler-to-2-1-21 branch August 19, 2025 09:21
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.

4 participants