solonovamax
03/08/2025, 10:35 PMfun configureProject() {
project.configure<KotlinProjectExtension> {
if (this is HasConfigurableKotlinCompilerOptions<*>)
configureCommonCompilerOptions()
when (this) {
is KotlinJvmProjectExtension -> {
configureJvmCompilerOptions()
}
is KotlinMultiplatformExtension -> {
targets.withType<KotlinJvmTarget>().configureEach {
configureJvmCompilerOptions()
}
targets.withType<KotlinJsIrTarget>().configureEach {
configureJsCompilerOptions()
}
}
}
}
}
private fun HasConfigurableKotlinCompilerOptions<*>.configureCommonCompilerOptions() {
val nyx = this@NyxKotlinExtension
compilerOptions {
// ...
}
}
however, the problem I'm facing is that when I add this plugin to another project and this code gets executed, then the following exception will be thrown:
Caused by: java.lang.ClassCastException: class org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension_Decorated cannot be cast to class org.jetbrains.kotlin.gradle.dsl.HasConfigurableKotlinCompilerOptions (org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension_Decorated and org.jetbrains.kotlin.gradle.dsl.HasConfigurableKotlinCompilerOptions are in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader$InstrumentingVisitableURLClassLoader @47f6e669)
this makes absolutely no sense as to why it's occurring, as KotlinJvmProjectExtension
definitely inherits from HasConfigurableKotlinCompilerOptions
.
if you would like to see exactly what I'm doing, then that can be found here:
https://github.com/solo-studios/nyx/blob/ae325df6221244572757ff661767621c8de01262/src/main/kotlin/ca/solostudios/nyx/plugin/compile/NyxKotlinExtension.kt#L370-L439
you can test this behaviour by doing the following in any gradle project:
first, add the following to your `settings.gradle.kts`:
pluginManagement {
repositories {
maven("<https://maven.solo-studios.ca/snapshots/>")
mavenCentral()
gradlePluginPortal()
}
resolutionStrategy {
eachPlugin {
if (requested.id.id == "ca.solo-studios.nyx") {
useModule("ca.solo-studios:nyx:0.3.0-20250308.223428-37")
}
}
}
}
then, add the following to your `build.gradle.kts`:
plugins {
id("ca.solo-studios.nyx") version "0.3.0-SNAPSHOT"
}
re-import the project, and it will fail.
the source code for the entire project can be found on github.
edit: I have published a workaround, so you need to do funny resolution stuff to get the broken version.Adam
03/09/2025, 7:46 PMsolonovamax
03/10/2025, 12:12 AMClassCastException
rather than a NoClassDefFoundError
.
I've never experienced that error, and even handle it in a few cases where both plugins might not be loaded: https://github.com/solo-studios/nyx/blob/master/src/main/kotlin/ca/solostudios/nyx/plugin/compile/NyxCompilePlugin.kt#L57-L67
try {
project.plugins.withType<KotlinBasePlugin> {
val kotlinExtension = compileExtension.create<NyxKotlinExtension>(NyxKotlinExtension.NAME, project, compileExtension)
project.afterEvaluate {
kotlinExtension.configureProject()
}
}
} catch (_: NoClassDefFoundError) {
// ignore
}
Vampire
03/12/2025, 4:05 PM