Sergey Chelombitko
06/16/2025, 4:06 PMkotlin-dsl plugin from a regular Project plugin with the default version?
I tried this way, it requires adding an explicit dependency org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin which I want to avoid.
class MyConventionPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.pluginManager.apply("org.gradle.kotlin.kotlin-dsl")
}
}ephemient
06/16/2025, 5:10 PMSergey Chelombitko
06/16/2025, 5:13 PMephemient
06/16/2025, 5:14 PMdependencies {
implementation(gradleKotlinDsl())
}
in your plugin/build.gradle.kts or however you have it set up, but
plugins {
`kotlin-dsl`
}
in a precompiled script plugin or
pluginManager.apply(org.gradle.kotlin.dsl.plugins.dsl.KotlinDslPlugin::class)
should just work, because it gets pulled in by gradleApi() which is a default dependency of java-gradle-plugin buildsephemient
06/16/2025, 5:15 PMpluginManager.apply("kotlin-dsl")?ephemient
06/16/2025, 5:16 PMSergey Chelombitko
06/16/2025, 5:25 PMpluginManager.apply(KotlinDslPlugin::class)
pluginManager.apply("org.gradle.kotlin.kotlin-dsl")
pluginManager.apply("kotlin-dsl")
pluginManager.apply("`kotlin-dsl`")
still, for what purpose is this?I have a convention plugin which applies kotlin-dsl internally. I can probably replace kotlin-dsl with a combination of java-gradle-plugin, sam-with-receiver and gradleKotlinDsl() dependency
Adam
06/16/2025, 8:13 PMimplementation("org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:6.1.2")
(coordinates from https://plugins.gradle.org/plugin/org.gradle.kotlin.kotlin-dsl, under "Adding the plugin to build logic for usage in precompiled script plugins.")Adam
06/16/2025, 8:14 PMSergey Chelombitko
06/16/2025, 10:31 PMAdam
06/17/2025, 5:28 AMAdam
06/17/2025, 5:31 AMAdam
06/17/2025, 5:33 AMbase plugin). It has a compileOnly dependency on kotlin-dsl. Users would still have to apply the kotlin-dsl plugin, but would also have to apply the custom-base plugin. And then the custom-base plugin would have a plugins.withType<KotlinDslPlugin>().configureEach {} (using the correct kotlin-dsl plugin class).Adam
06/17/2025, 5:37 AMorg.gradle.plugin.api‑version attribute to create variants per Gradle version. Each variant would use the correct kotlin-dsl version (org.gradle.kotlin.dsl.support.expectedKotlinDslPluginsVersion) per Gradle version
https://docs.gradle.org/8.14.2/userguide/variant_attributes.html#sec:gradle-plugins-default-attributesVampire
06/17/2025, 11:11 AMkotlin-dsl plugin is not a built-in plugin. It is an external plugin pulled in from plugin central which just has a special build-time generated accessor that applies that external plugin with a specific version and checks that is the plugin is applied it is applied in a specific version. I have no idea why it is made like that, but it should probably better be built-in.
Even for a specific Gradle version there is no way to get the version to depend on besides an internal constant: https://github.com/gradle/gradle/issues/17825
It probably indeed would be the only option currently to have one variant per Gradle version that depends on the according plugin version.
Most probably it would be much easier to just not do it but let the customer apply the plugin himself.
plugins.wthType should practically never be used, look at the JavaDoc of plugins. (i.e. getPlugins()). You should not use it, but pluginManager.withPlugin instead.