Guilherme Delgado
09/14/2022, 3:17 PMplugins {
kotlin("multiplatform")
id("org.jetbrains.compose") version Versions.JetBrains.Compose.desktop
}
to a convention plugin where:
with(pluginManager) {
apply("org.jetbrains.kotlin.multiplatform:${catalog.findVersion("kotlin").get()}")
apply("org.jetbrains.compose:${catalog.findVersion("desktopCompose").get()}")
}
but when I run it throws saying (same for the second line if I comment the first):
Caused by: org.gradle.api.plugins.UnknownPluginException: Plugin with id 'org.jetbrains.kotlin.multiplatform:1.7.10' not found.
at org.gradle.api.internal.plugins.DefaultPluginManager.apply(DefaultPluginManager.java:144)
I’ve checked here and the syntax of the plugin is correct. What am I missing here? 🤔
Thanks!Sam
09/14/2022, 3:28 PMapply
call and the buildscript
dependency. (And the version number goes in the buildscript dependency).Sam
09/14/2022, 3:28 PMGuilherme Delgado
09/14/2022, 3:31 PMGuilherme Delgado
09/14/2022, 3:31 PMwith(pluginManager) {
apply("org.jetbrains.kotlin.multiplatform:${catalog.findVersion("kotlin").get()}")
apply("org.jetbrains.compose:${catalog.findVersion("desktopCompose").get()}")
}
Guilherme Delgado
09/14/2022, 3:32 PMGuilherme Delgado
09/14/2022, 3:32 PMephemient
09/14/2022, 3:33 PMGuilherme Delgado
09/14/2022, 3:34 PMephemient
09/14/2022, 3:34 PMGuilherme Delgado
09/14/2022, 3:52 PMwith(pluginManager) {
dependencies {
add(
ephemient
09/14/2022, 3:55 PM// plugin/build.gradle
dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10")
}
// plugin/src/main/kotlin/my-convention-plugin.gradle.kts
plugins {
kotlin("multiplatform")
}
// or plugins/src/main/kotlin/my/convention/MyPlugin.kt
class MyPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.pluginManager.apply("org.jetbrains.kotlin.multiplatform")
Guilherme Delgado
09/14/2022, 3:56 PMGuilherme Delgado
09/14/2022, 3:56 PMGuilherme Delgado
09/14/2022, 3:57 PMid("org.jetbrains.compose") version Versions.JetBrains.Compose.desktop
into to a convention plugin “import”Guilherme Delgado
09/14/2022, 3:57 PMGuilherme Delgado
09/14/2022, 3:58 PMGuilherme Delgado
09/14/2022, 3:58 PMwith(pluginManager) {
val catalog = extensions.getByType<VersionCatalogsExtension>().named("libs")
dependencies {
add("implementation", "org.jetbrains.compose") {
setVersion(catalog.findVersion("desktopCompose"))
}
}
apply("org.jetbrains.kotlin.multiplatform")
...
}
ephemient
09/14/2022, 4:00 PMGuilherme Delgado
09/14/2022, 4:01 PMGuilherme Delgado
09/14/2022, 4:03 PMGuilherme Delgado
09/14/2022, 4:04 PMGuilherme Delgado
09/14/2022, 4:04 PMandroid {
compileSdk = libs.findVersion("androidCompileSdk").get().toString().toInt()
}
that can be used in shared modules that require android library, etc.ephemient
09/14/2022, 4:04 PM// plugin/settings.gradle.kts
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
// plugins/build.gradle.kts
dependencies {
implementation("org.jetbrains.compose:compose-gradle-plugin:${libs.versions.desktopCompose.get()}"
isto
09/15/2022, 3:34 PM// buildSrc/settings.gradle.kts
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
// enable sharing of libs catalog between buildSrc stuff and app modules
from(files("../gradle/libs.versions.toml"))
}
}
}
// buildSrc/build.gradle.kts
plugins {
`kotlin-dsl`
}
repositories {
gradlePluginPortal()
}
dependencies {
// plugins applied from script plugins need to be defined as dependencies here
implementation(kotlin("gradle-plugin", libs.versions.kotlin.get()))
implementation("com.github.ben-manes:gradle-versions-plugin:0.42.0")
implementation("org.owasp:dependency-check-gradle:7.0.0")
}
kotlin {
jvmToolchain {
(this as JavaToolchainSpec).languageVersion.set(JavaLanguageVersion.of(libs.versions.jvm.get()))
}
}
// buildSrc/src/main/kotlin/myapp.conventions.gradle.kts
plugins {
// NOTE: no version definitions here, versions are defined as part of dependencies in buildSrc/build.gradle.kts,
// in plugins block there's no Project, so the Ext.kt approach (see below) does no work here
java
kotlin("jvm")
}
// NOTE: libs are not directly accessible in script plugins, but we can get to them via Project, see Ext.kt
val jvmVersion = requiredVersionFromLibs("jvm")
kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(jvmVersion))
}
}
// buildSrc/src/main/kotlin/Ext.kt
// <https://github.com/gradle/gradle/issues/15383>
private val Project.libsCatalog get() = the<VersionCatalogsExtension>().named("libs")
fun Project.requiredVersionFromLibs(name: String) = libsCatalog.findVersion(name).get().requiredVersion
fun Project.dependencyFromLibs(name: String) = libsCatalog.findLibrary(name).get()
// myapp/build.gradle.kts
// NOTE: here libs is available
plugins {
id("myapp.conventions")
alias(libs.plugins.somePluginDefinedInCatalogThatsNotAppliedByScriptPlugins)
}
Guilherme Delgado
09/15/2022, 3:43 PMGuilherme Delgado
09/15/2022, 8:06 PMplugins {
kotlin("multiplatform")
alias(libs.plugins.jetbrains.compose)
}
:sharedComposables
plugins {
id("buildlogic.plugins.conventions.kmp.library.android")
alias(libs.plugins.jetbrains.compose)
}
where my versions are declared as:
[plugins]
jetbrains-compose = { id = "org.jetbrains.compose", version.ref = "desktopCompose" }
🥳
ps: My KMPAndroidLibraryConventionPlugin `id("buildlogic.plugins.conventions.kmp.library.android")`it’s also used in :shared (KMM module) and it contains Android configurations like defaultConfig
, compileOptions
, lint
, etc… and it also applies:
pluginManager.apply("org.jetbrains.kotlin.multiplatform")
pluginManager.apply("com.android.library")
I’ve also kept the compose version outside the plugin 🙂