Guilherme Delgado
06/20/2022, 2:10 PMclass KotlinJvmOptionsPlugin : Plugin<Project> {
    override fun apply(target: Project) {
        with(target) {
            extensions.configure<KotlinJvmOptions> {
                jvmTarget = "11"
                freeCompilerArgs = freeCompilerArgs + listOf("-Xopt-in=kotlin.RequiresOptIn")
            }
        }
    }
}Caused by: org.gradle.api.UnknownDomainObjectException: Extension of type 'KotlinJvmOptions' does not exist. Currently registered extension types: [ExtraPropertiesExtension, BasePluginExtension, DefaultArtifactPublicationSet, SourceSetContainer, ReportingExtension, JavaPluginExtension, JavaToolchainService, NamedDomainObjectContainer<BaseVariantOutput>, LibraryExtension, LibraryAndroidComponentsExtension]kotlinOptionsGuilherme Delgado
06/20/2022, 2:18 PMhfhbd
06/20/2022, 2:20 PMproject.configure<FooExtension> { }Vampire
06/20/2022, 2:37 PMKotlinJvmOptionsLibraryExtensionCommonExtensionextensions.configureconfigurethispluginManager.withPluginGuilherme Delgado
06/20/2022, 2:44 PMclass KotlinJvmOptionsPlugin : Plugin<Project> {
    override fun apply(target: Project) {
        with(target) {
            configure<LibraryExtension> {
                (this as ExtensionAware).extensions.configure<KotlinJvmOptions>("kotlinOptions") {
                    jvmTarget = "11"
                    freeCompilerArgs = freeCompilerArgs + listOf("-Xopt-in=kotlin.RequiresOptIn")
                }
            }
        }
    }
}Guilherme Delgado
06/20/2022, 2:45 PMBut one important thing to notice, if you write it like that, you introduce an ordering constraint for plugins. Your plugin will onyl work if it is applied after the Kotlin plugin. Such ordering constraints for plugins are bad practice. Better useThis is a good advice because i was having this problem and I didn’t knew what it was. 🙌to react to the Kotlin plugin being applied for configuring it.pluginManager.withPlugin
Guilherme Delgado
06/20/2022, 2:46 PMpluginManager.withPlugin@Suppress("UnstableApiUsage", "unused")
class KotlinJvmOptionsPlugin : Plugin<Project> {
    override fun apply(target: Project) {
        with(target) {
            with(pluginManager) {
                apply("com.android.library")
                apply("org.jetbrains.kotlin.android")
            }
            
            configure<LibraryExtension> {
                (this as ExtensionAware).extensions.configure<KotlinJvmOptions>("kotlinOptions") {
                    jvmTarget = "11"
                    freeCompilerArgs = freeCompilerArgs + listOf("-Xopt-in=kotlin.RequiresOptIn")
                }
            }
        }
    }
}Guilherme Delgado
06/20/2022, 2:51 PMVampire
06/20/2022, 3:19 PMRegarding pluginNo, I did not sayyour suggestion is to do something like this:pluginManager.withPlugin
pluginManager.applypluginManager.withPluginapplypluginManagerProjectapplypluginManager.withPluginpluginManager.withPluginVampire
06/20/2022, 3:20 PMGuilherme Delgado
06/20/2022, 3:24 PM