Search code examples
kotlingradleintellij-ideaplugins

'Unsolved reference: kotlin' when using default template for plugin creation (IntelliJ)


I want to develop a Plugin for IntelliJ. My version is 2023.2.5. For that I used the New Project wizard with JDK 17. The build.gradle.kts looks like this:

plugins {
    id("java")
    id("org.jetbrains.kotlin.jvm") version "1.9.20"
    id("org.jetbrains.intellij") version "1.15.0"
}

group = "com.example"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

// Configure Gradle IntelliJ Plugin
// Read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html
intellij {
    version.set("2022.2.5")
    type.set("IC") // Target IDE Platform

    plugins.set(listOf(/* Plugin Dependencies */))
}

tasks {
    // Set the JVM compatibility versions
    withType<JavaCompile> {
        sourceCompatibility = "17"
        targetCompatibility = "17"
    }
    withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
        kotlinOptions.jvmTarget = "17"
    }

    patchPluginXml {
        sinceBuild.set("222")
        untilBuild.set("232.*")
    }

    signPlugin {
        certificateChain.set(System.getenv("CERTIFICATE_CHAIN"))
        privateKey.set(System.getenv("PRIVATE_KEY"))
        password.set(System.getenv("PRIVATE_KEY_PASSWORD"))
    }

    publishPlugin {
        token.set(System.getenv("PUBLISH_TOKEN"))
    }
}

I have installed the Gradle and Kotlin plugin and set my projekt SDK to JDK 17. Yet when I use this import:

import org.jetbrains.kotlin.jvm

I get the error: 'Unresolved reference: kotlin'. I haven't changed the template at all, so I can't pin down the error

I tried changing the SDK to the Kotlin SDK and made sure that the version of JVM target matches the JDK i used. The documentation does not specify what to do when an error occurs and just expects the wizard to behave normally, so I'm really lost here


Solution

  • I had to add org.jetbrains.kotlin as a dependency manually. also kotlin was somehow disabled in the gradle.properties per default so i had to turn that back on. thenit worked after rebuilding