After updating to Kotlin 1.9.0 I'm no longer able ...
# gradle
a
After updating to Kotlin 1.9.0 I'm no longer able to call:
Copy code
android {
    withGroovyBuilder {
        "kotlinOptions" {
            setProperty("jvmTarget", "1.8")
        }
    }
}
It throws "Could not find method kotlinOptions() for arguments ...". Looking at the "What's new" of the 1.9.0 release (link), it mentions the following:
Copy code
kotlin {
    compilerOptions {
        jvmTarget.set(...)
    }
}
But that doesn't work either: "Unresolved reference: compilerOptions". How can I set
jvmTarget
now?
m
Maybe this?
Copy code
tasks.withType(KotlinCompile::class.java).configureEach {
  kotlinOptions {
    jvmTarget.set(...)
  }
}
Ah, sorry, you might have to cast too:
Copy code
tasks.withType(KotlinCompile::class.java).configureEach {
    kotlinOptions {
      (this as? KotlinJvmOptions)?.let {
        it.jvmTarget = "1.8"
      }
    }
  }
a
Thanks! I was able to write it as follows:
Copy code
tasks.withType<KotlinCompile> {
        kotlinOptions {
            jvmTarget = "1.8"
        }
    }
Wondering, why the guide says something that is not working?
t
Generally how
kotlinOptions
are added into android extension was not changed in 1.9.0 - it is added via
ExtensionAware
here. And
kotlin.compilerOptions {}
DSL should also be available. Please check that you are using 1.9.0 Kotlin Gradle Plugin version and not some older one
a
Ah ok, that might be the old Kotlin Gradle Plugin in AS Giraffe. I will try with IDEA. Thanks!
Well, I have the following code, that is no working with Kotlin 1.9.0, but works with 1.8.20. I was able to use
tasks.withType
instead, but still maybe it rings the bell?
Copy code
internal fun Project.setupAndroidCommon() {
    extensions.configure<BaseExtension> {
        withGroovyBuilder {
            "kotlinOptions" {
                setProperty("jvmTarget", "1.8")
            }
        }
    }
}
t
that is strange. As I said - there were no changes in
KotlinJvmOptions
itself + how it is added into Android extension 🤔
do you have a repro project?
a
I will try to provide a reproducer a bit later, currently struggling with other issues while updating to Kotlin 1.9.0. 😀
👌 1