I'm trying to create a gradle plugin as part of a ...
# community-support
r
I'm trying to create a gradle plugin as part of a library project. The
gradleApi()
dependency function isn't available inside sourceSets/jvmMain/dependencies, but it is available in a root dependencies block. However, in the latter location, it still isn't enough for my plugin class to be able to import anything from org.gradle. Build file in thread
Copy code
plugins {
    kotlin("multiplatform") version "2.0.20"
    kotlin("plugin.serialization") version "2.0.20"
    id("com.github.node-gradle.node") version "7.0.2"
    id("maven-publish")
    `java-gradle-plugin`
}

group = "zoned"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
    gradlePluginPortal()
}

val kotlinWrappers = "1.0.0-pre.819"

// works here
//dependencies {
//    implementation(gradleApi())
//    implementation(kotlin("gradle-plugin"))
//}

kotlin {
    jvm()
    js(IR) {
        browser()
        nodejs()
    }

    sourceSets {
        val jsMain by getting {
            dependencies {
                api(project.dependencies.platform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:$kotlinWrappers"))
                api("org.jetbrains.kotlin-wrappers:kotlin-js")
                api("org.jetbrains.kotlin-wrappers:kotlin-browser")
                api("org.jetbrains.kotlin-wrappers:kotlin-css")

                api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.3")
                api("org.jetbrains.kotlinx:kotlinx-html-js:0.11.0")
                api(npm("tailwindcss", "3.4.4"))
                api(npm("sortablejs", "1.15.1"))
            }
        }
        val jvmMain by getting {
            dependencies {
                // but not here
                implementation(gradleApi())
                implementation(kotlin("gradle-plugin"))
                implementation("com.github.node-gradle:gradle-node-plugin:7.0.2")
            }
        }
    }
}

gradlePlugin {
    plugins {
        create("zonedjsPlugin") {
            id = "${project.group}.${project.name}"
            implementationClass = "zoned.gradle.ZonedPlugin"
        }
    }
}

// Publishing configuration
publishing {
    publications {
        create<MavenPublication>("maven") {
            from(components["kotlin"])
        }
    }

    // Configure the repository to publish to
    repositories {
        mavenLocal()
    }
}
Ah. Buried in the build output (but not visible in the IDE):
w: 'java' Gradle plugin is not compatible with 'org.jetbrains.kotlin.multiplatform' plugin.
What's the reason for the incompatibility?
v
Ask JetBrains? Probably the KMP plugin and
java
plugin do incompatible things.
Regarding "but not here", you could probably use the usual work-around
implementation(dependencies.gradleApi())
.
p
Why exactly do you want to mix a JVM graded plugin with Kotlin Multiplattform? Yes, t should work, but I really recommend you to split the modules because it’s way easier. Eg both plugins configure publishing automatically, but it might be not compatible, eg pom marker and MPP POM rewriting.