Slackbot
04/27/2022, 10:33 PMephemient
04/27/2022, 10:39 PMplugins, pluginManagement is special and is executed in a first pass outside of the context of the rest of the build scriptephemient
04/27/2022, 10:41 PMZak Taccardi
04/27/2022, 10:44 PMplugins {
alias(libs.plugins.ktlint)
}
but I think IDE support (at least in Android Studio) here is lackingephemient
04/27/2022, 10:46 PMVampire
04/27/2022, 10:52 PMpluginManagement { ... } block it were right, that it is handled separately first.
I think when accessing it like pluginManagement.... then it is done during normal settings script evaluation.
But nevertheless it is of course still hen-and-egg problem, as the version catalog is not defined in such an "evaluated before" block but in dependencyResolutionManagement and thus during normal settings script evaluation and thus the accessors can not yet be available during settings script evaluation.
The reason for this is, that a settings plugin can define a version catalog to be used in the project.
So yes, the alias(libs.plugins ... is the idiomatic way and yes, the IntelliJ Kotlin plugin still lacks of proper support for it, while it still works fine of course as far as Gradle is concerned. And in the issue ephemient linked, you can find a small work-around plugin that just suppresses these red highlightings if you really care that much about it.ephemient
04/27/2022, 10:55 PMpluginManagement.* won't be extracted, only pluginManagement { * }. but it still won't work for the reasons Bjรถrn mentions.Zak Taccardi
04/27/2022, 11:09 PMbuildSrc/build.gradle.kts):
dependencies {
/**
* Workaround for <https://gradle-community.slack.com/archives/CAHSN3LDN/p1651098827826449>
*/
@Suppress("NAME_SHADOWING")
fun DependencyHandlerScope.implementationGradlePlugin(id: String, version: Provider<String>) {
implementation(version.map { version -> "$id:$id.gradle.plugin:$version" })
}
implementationGradlePlugin("de.undercouch.download", libs.versions.downloadGradlePlugin)
implementationGradlePlugin("org.jlleitschuh.gradle.ktlint", libs.versions.ktlintGradlePlugin)
}
where libs.versions.ktlintGradlePlugin refers to the version in the version catalogZak Taccardi
04/27/2022, 11:11 PMbuildSrc plugin:
plugins {
id("de.undercouch.download")
id("org.jlleitschuh.gradle.ktlint")
}ephemient
04/27/2022, 11:12 PMplugins { alias } and ignore the IDE error, it makes no difference.Zak Taccardi
04/27/2022, 11:13 PMephemient
04/27/2022, 11:14 PMGlen Peterson
05/03/2022, 3:44 PMplugins {
@Suppress("DSL_SCOPE_VIOLATION")
alias(libs.plugins.m.versions)
}Vampire
05/03/2022, 3:45 PM