'How to use Kotlin with a Bukkit/Spigot plugin and Gradle

I am trying to use Kotlin for a Spigot plugin (for version 1.8.8), as I find Kotlin a lot more efficient to use. But, whenever I try and run the plugin, I get this error:

Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics

I have looked online, and it seems I need to shade the Kotlin jar file into my plugin, could anyone advise me how I would do that?

UPDATE After trying what was suggested below I still get the same error. Here is my build.gradle:

plugins {
    id 'java'
    id 'org.jetbrains.kotlin.jvm' version '1.3.31'
    id 'com.github.johnrengelman.shadow' version '4.0.2'
}

group 'me.graphicalcake95'
version '1.0.0'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
    maven {
        url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
    }
}

shadowJar {
    baseName = 'shadow'
    classifier = null
    version = null
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compileOnly 'org.bukkit:bukkit:1.8.8-R0.1-SNAPSHOT'
    shadow "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
}
compileKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}
compileTestKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}


Solution 1:[1]

You indeed need to Shadow the Kotlin standard library into your plugin. Since you are using Gradle it can do this by using the Shadow Plugin which is similar to Shade but Shade is only for Maven so it won't be useful for you.

Using the Shadow plugin is straightforward. First you apply the plugin itself:

plugins {
  id 'com.github.johnrengelman.shadow' version '5.0.0'
}

then you can configure Shadow:

shadowJar {
   baseName = 'shadow'
   classifier = null
   version = null
}

This will create a shadow.jar in your build folder when you build the project. After applying the shadow plugin you can shadow dependencies to be included in the fat jar:

dependencies {
  shadow "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
}

Solution 2:[2]

Install this plugin on your spigot server download the jar and place it in the plugins folder, then follow the documentation

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Adam Arold
Solution 2