-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Migrate KotlinCompile configuration to compilerOptions DSL #375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Import looks right; confirm Kotlin Gradle Plugin version supports JvmTarget/compilerOptions
This import is required for
JvmTarget.fromTarget(...). Ensure the repo is on Kotlin Gradle Plugin ≥ 1.9 socompilerOptionsand this enum are available. Also verify there aren’t olderkotlinOptions { ... }blocks hanging around in submodules that could conflict.Run:
🏁 Script executed:
Length of output: 3063
The leftover
kotlinOptions { … }block was found inbenchmark/build.gradle.ktsand must be updated or removed to avoid conflicts with the newcompilerOptionsAPI. We still need to confirm the exact Kotlin plugin version from the catalog to ensure it’s ≥ 1.9 (required forJvmTarget.fromTargetandcompilerOptions).Please address the following:
kotlinOptions { … }block inbenchmark/build.gradle.kts:25-> Replace with the newer
compilerOptions { jvmTarget.set(…) }syntax as appropriate.gradle/libs.versions.toml:[versions] kotlin = "…"entry is 1.9.x or higher.Once the Kotlin version is confirmed ≥ 1.9 and the old
kotlinOptionsblock is removed, the import oforg.jetbrains.kotlin.gradle.dsl.JvmTargetand use ofcompilerOptionswill be safe.🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that the
benchmark/build.gradle.ktsmodule had a leftoverkotlinOptionsblock.I attempted to migrate it to
compilerOptions, but this test-only module doesn’t seem to expose that DSL (with AGP 8.12.1 + Kotlin 2.1.10 it results inUnresolved reference 'compilerOptions').There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
I need to examine the benchmark module to understand why
compilerOptionsisn't available and determine the best approach for handling the leftoverkotlinOptionsblock.🏁 Script executed:
Length of output: 3261
@XDdevv, I see the issue! The
kotlinOptionsblock in your benchmark module is in a different context than the ones we migrated in the rootbuild.gradle.kts.The
kotlinOptionsin your benchmark module is inside theandroidblock (lines 25-27), which is Android Gradle Plugin territory, not aKotlinCompiletask configuration. This is whycompilerOptionsisn't available there.Here are your options:
build.gradle.ktsalready configures allKotlinCompiletasks in subprojects (including benchmark), thekotlinOptionsin the benchmark module'sandroidblock is likely redundant:android { namespace = "com.skydoves.pokedex.benchmark" // Remove this block - it's redundant with root configuration // kotlinOptions { // jvmTarget = "11" // } defaultConfig { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } // ... rest of config }android { namespace = "com.skydoves.pokedex.benchmark" compileOptions { sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 } // ... rest of config }I recommend option 1 since your root build configuration already handles this consistently across all modules.
🏁 Script executed:
Length of output: 1053
Perfect! Now I can see that your root
build.gradle.ktsalready configures all subprojects (including the benchmark module) with:This means the
kotlinOptions { jvmTarget = "11" }block in your benchmark module'sandroidblock is redundant and should be removed.Recommendation: Simply delete the
kotlinOptionsblock frombenchmark/build.gradle.kts:android { namespace = "com.skydoves.pokedex.benchmark" - kotlinOptions { - jvmTarget = "11" - } defaultConfig { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } // ... }The JVM target will be handled consistently by the root configuration along with all other Kotlin compilation settings. This approach keeps your build configuration DRY and ensures consistency across all modules.
🏁 Script executed:
Length of output: 741
Perfect! Now I have all the information. The root
build.gradle.ktsuses:bytecodeVersion = JavaVersion.toVersion(libs.versions.jvmBytecode.get())jvmTarget.set(JvmTarget.fromTarget(bytecodeVersion.toString()))This configuration applies to all subprojects, including your benchmark module. The
kotlinOptions { jvmTarget = "11" }in your benchmark module'sandroidblock is redundant and should be removed.Final recommendation: Delete the
kotlinOptionsblock frombenchmark/build.gradle.kts:android { namespace = "com.skydoves.pokedex.benchmark" - kotlinOptions { - jvmTarget = "11" - } defaultConfig { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } // ... }The JVM target will be consistently managed by the root build configuration's
compilerOptionsDSL, ensuring all modules use the same version defined in your version catalog.🏁 Script executed:
Length of output: 219095
Perfect! Now I can see the complete picture. The version catalog shows
jvmBytecode = "11", which means:bytecodeVersion = JavaVersion.toVersion(libs.versions.jvmBytecode.get())which resolves to Java 11kotlinOptions { jvmTarget = "11" }jvmTarget.set(JvmTarget.fromTarget(bytecodeVersion.toString()))@XDdevv, you're absolutely correct! The
kotlinOptionsblock in your benchmark module'sandroidblock is indeed redundant. Here's what's happening:build.gradle.ktsalready configures this: Thetasks.withType<KotlinCompile>()block applies to all subprojects, including the benchmark modulejvmBytecode = "11"and your benchmark module hardcodesjvmTarget = "11"compilerOptionsDSL works onKotlinCompiletasks, whilekotlinOptionsin theandroidblock is Android Gradle Plugin specificRecommendation: Simply remove the entire
kotlinOptionsblock frombenchmark/build.gradle.kts:android { namespace = "com.skydoves.pokedex.benchmark" - kotlinOptions { - jvmTarget = "11" - } defaultConfig { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } // ... rest of config }The JVM target will be handled consistently by your root build configuration. This keeps your build setup clean and avoids the "Unresolved reference 'compilerOptions'" error since you don't need module-specific Kotlin configuration anyway.
🏁 Script executed:
Length of output: 6853
Great! Now I can see the full picture. There's actually a version discrepancy that's worth pointing out:
Version Analysis
jvmBytecode = "17"(Java 17)JavaVersion.toVersion(libs.versions.jvmBytecode.get())→ Java 17jvmTarget = "11"→ Java 11@XDdevv, your benchmark module is currently using Java 11 while the rest of your project uses Java 17. This inconsistency will be resolved when you remove the redundant
kotlinOptionsblock.Recommendation
Remove the entire
kotlinOptionsblock frombenchmark/build.gradle.kts:android { namespace = "com.skydoves.pokedex.benchmark" - kotlinOptions { - jvmTarget = "11" - } defaultConfig { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } // ... rest of config }What This Achieves
The root build configuration's
compilerOptionswill handle the JVM target for all modules consistently.✏️ Learnings added