Working on a Mod for Spigot/Minecraft (Class Not Found Err)

Wanted to make a quick skeleton project to show what my issue is. I’m wanting to use Kotlin to develop a mod using Spigot for Minecraft, but I’m getting an error “java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics”. I’ve read several different things and am not sure what the solution is.

I’ve heard of a shadow jar or something? Not sure what that is. I’m hoping that there is a straightforward solution though! :sweat_smile:

Walkthrough

New Project -> Kotlin JVM

/hello -> Error Log:

Summary
[Server thread/WARN]: Unexpected exception while parsing console command "hello"
org.bukkit.command.CommandException: Unhandled exception executing command 'hello' in plugin KotlinSkeleton v1.0.0
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[spigot-1.14.4.jar:git-Spigot-798ea6a-368f4e9]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[spigot-1.14.4.jar:git-Spigot-798ea6a-368f4e9]
at org.bukkit.craftbukkit.v1_14_R1.CraftServer.dispatchCommand(CraftServer.java:710) ~[spigot-1.14.4.jar:git-Spigot-798ea6a-368f4e9]
at org.bukkit.craftbukkit.v1_14_R1.CraftServer.dispatchServerCommand(CraftServer.java:695) [spigot-1.14.4.jar:git-Spigot-798ea6a-368f4e9]
at net.minecraft.server.v1_14_R1.DedicatedServer.handleCommandQueue(DedicatedServer.java:430) [spigot-1.14.4.jar:git-Spigot-798ea6a-368f4e9]
at net.minecraft.server.v1_14_R1.DedicatedServer.b(DedicatedServer.java:394) [spigot-1.14.4.jar:git-Spigot-798ea6a-368f4e9]
at net.minecraft.server.v1_14_R1.MinecraftServer.a(MinecraftServer.java:970) [spigot-1.14.4.jar:git-Spigot-798ea6a-368f4e9]
at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:815) [spigot-1.14.4.jar:git-Spigot-798ea6a-368f4e9]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_221]
Caused by: java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics
at com.talvysh.kotlinskeleton.KotlinCmd.onCommand(KotlinCmd.kt) ~[?:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot-1.14.4.jar:git-Spigot-798ea6a-368f4e9]
... 8 more
Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics
at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_221]
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:135) ~[spigot-1.14.4.jar:git-Spigot-798ea6a-368f4e9]
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:81) ~[spigot-1.14.4.jar:git-Spigot-798ea6a-368f4e9]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_221]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_221]
at com.talvysh.kotlinskeleton.KotlinCmd.onCommand(KotlinCmd.kt) ~[?:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot-1.14.4.jar:git-Spigot-798ea6a-368f4e9]
... 8 more

KotlinSkeleton.kt

package com.talvysh.kotlinskeleton

import org.bukkit.plugin.java.JavaPlugin

public class KotlinSkeleton: JavaPlugin(){
    override fun onEnable() {
        logger.info("Enabled.")
        getCommand("hello")?.setExecutor(KotlinCmd())
    }

    override fun onDisable() {}
}

KotlinCmd.kt

package com.talvysh.kotlinskeleton

import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender

public class KotlinCmd: CommandExecutor{
    override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
        if(label.equals("hello", true)) {
            sender.sendMessage("Hello, World!")
            return true
        }

        return false
    }
}

Additional Info

Modules -> Dependencies:

  • Spigot.jar
  • Spigot API folder

Artifacts -> Output Layout

  • KotlinJavaRuntime
  • ‘KotlinSkeleton’ compile output

Everything else is left default.

The problem is that the runtime can’t find the kotlin standard library. If you are building with gradle or maven the solution would be using the shadow plugin. There are multiple tutorials on how to do that on the internet. Just search “kotlin shadowjar gradle” or “kotlin shadowjar maven” and you should find plenty of examples on how to do that.
I’m not sure how to set this up using Intellij’s build system. You need to either include the standard-lib into your own jar or link to it using the manifest file and copy the standard-lib along with your jar.
As far as I can tell you can set this up when you create the artifact under “JAR files from libraries”. Not sure how to change that later.