Search code examples
gradleintellij-ideaintellij-plugin

java.lang.NoClassDefFoundError in Intellij Plugin


I'm trying to build a plugin for Intellij but I'm getting a java.lang.NoClassDefFoundError at runtime every time my code point to a class in another module or to an external library.

Everything works fine in my tests and in the sandbox via runIde.

I also managed to reproduce the error by creating a new project with just an action and a module with a class and an empty method.

root gradle:

buildscript {
    ext.kotlin_version = '1.2.31'

    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

plugins {
    id 'org.jetbrains.intellij' version '0.3.12'
}

group 'test'
version '1.0-SNAPSHOT'

apply plugin: 'kotlin'

repositories {
    mavenCentral()
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    compile project(':testmodule')
}

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
intellij {
    version '2018.1.6'
}
patchPluginXml {
    changeNotes """
      Add change notes here.
most HTML tags may be used""" }

action:

package action

import com.intellij.openapi.actionSystem.*
import packages.OtherModuleClass

class TestAction : AnAction() {
    override fun actionPerformed(e: AnActionEvent?) {
        OtherModuleClass().otherModuleMethod()
    }
}

other module class:

package packages

class OtherModuleClass {

    fun otherModuleMethod() {}

}

Solution

  • I found out what my problem was.

    I was installing in my IDE the jar in build/libs instead of the zip in build/distributions.