https://kotlinlang.org logo
#gradle
Title
# gradle
a

Arjan van Wieringen

01/27/2023, 3:57 PM
I still am unable to figure out how to make a convention plugin that just applies Compose....It's driving me nuts. See thread for my current code for the plugin.
Copy code
# build-tools/settings.gradle.kts
rootProject.name = "build-tools"

include(":plugins")
Copy code
# build-tools/plugins/build.gradle.kts
plugins {
    `kotlin-dsl`
}

repositories {
    gradlePluginPortal()
    google()
    mavenCentral()
    maven("<https://maven.pkg.jetbrains.space/public/p/compose/dev>")
}

dependencies {
    implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0")
    implementation("org.jetbrains.compose:compose-gradle-plugin:1.2.1")
}
Copy code
# build-tools/plugins/src/main/kotlin/compose-desktop
plugins {
    kotlin("multiplatform")
    id("org.jetbrains.compose")
}

repositories {
    google()
    mavenCentral()
    maven("<https://maven.pkg.jetbrains.space/public/p/compose/dev>")
}

compose {
    kotlinCompilerPlugin.set("1.4.0")
}

kotlin {
    jvm()

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(compose.desktop.currentOs) {
                    exclude("org.jetbrains.compose.material", "material")
                    exclude("org.jetbrains.compose.material3", "material3")
                }
            }
        }
    }
}
And now I get:
Caused by: org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not find org.jetbrains.compose.compiler:compiler:1.4.0.
when I include this plugin in a project.
I tried to follow the guides in https://github.com/jjohannes/understanding-gradle#readme but if I want to do something slightly different I get these errors..... I seem to lack a complete sense of how Gradle works somehow.
h

hfhbd

01/27/2023, 4:05 PM
I think you just forgot to add the compose-jb repo to your actually projects
Wait, sorry, you already have the repo block in your convention plugin.
a

Arjan van Wieringen

01/27/2023, 4:09 PM
I found out it works when using Kotlin 1.7.20 and no manual setting of the Compose Compiler plugin
But that is still strange...
h

hfhbd

01/27/2023, 4:11 PM
Yeah...
a

Arjan van Wieringen

01/27/2023, 4:12 PM
It works now, I made a typo.... 😞
Copy code
compose {
    kotlinCompilerPlugin.set("1.4.0")
}
Should be
Copy code
compose {
    kotlinCompilerPlugin.set("androidx.compose.compiler:compiler:1.4.0")
}
Time to call it quits for the day
h

hfhbd

01/27/2023, 4:13 PM
Oh 😄 btw you could also define your repos in settings.gradle.kts for all projects
Copy code
dependencyResolutionManagement {
  repositories {
    mavenCentral()
    google()
    maven("<https://maven.pkg.jetbrains.space/public/p/compose/dev>")
  }
}
a

Arjan van Wieringen

01/27/2023, 4:13 PM
yeah, that's better I suppose
h

hfhbd

01/27/2023, 4:15 PM
Especially you can forbid/ignore repos added by a plugin/project for security reasons by setting
repositoriesMode
a

Arjan van Wieringen

01/27/2023, 4:17 PM
But that dependencyResolutionManagement in the build-tools settings is only for the fetching of the dependencies in the subsequent build scripts. Not for the actual compiled convention plugin codes right?
h

hfhbd

01/27/2023, 4:20 PM
I don't know, what you mean. "compiled convention" plugins are normal plugins. Gradle generates the id descriptor for gradle.kts files. So dependencyResolutionManagement is valid for all projects and their applied plugins.
a

Arjan van Wieringen

01/27/2023, 4:22 PM
You are right. My IDE complained when I moved it all and it didn't build. But after a refresh of the Gradle project it worked.
I appreciate your help enormously btw
h

hfhbd

01/27/2023, 4:26 PM
Yeah IDE support is still a problem if you have errors in your build logic, very annoying but I don't think a solution exists.
11 Views