Search code examples
kotlinintellij-plugin

IntelliJ Plugin Development. Class loader exception when start debugging


  1. I'm creating a Plugin Project using Gradle build system
  2. With following plugin.xml file content

<idea-plugin>
  <id>com.magicbytes.kotlin-converter-plugin</id>
  <name>Kotlin Converter Gradle</name>
  <vendor email="support@yourcompany.com" url="http://www.yourcompany.com">YourCompany</vendor>

  <description>
    <![CDATA[
    Enter short description for your plugin here.<br>
    <em>most HTML tags may be used</em>
    ]]></description>

  <!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description -->
  <idea-version since-build="162" />

  <!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
         on how to target different products -->
  <!-- uncomment to enable plugin in all products
    <depends>com.intellij.modules.lang</depends>
    -->

  <extensions defaultExtensionNs="com.intellij">
  </extensions>

  <actions>
    <group id="MyPlugin.SampleMenu" text="Greeting" description="Greeting menu">
      <add-to-group group-id="MainMenu" anchor="last" />
      <action id="Myplugin.Textboxes" class="ThirdAction" text="Hello" description="Says hello" />
    </group>
  </actions>
</idea-plugin>

  1. And Gradle build file content

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

group 'com.magicbytes'
version '0.0.1'

apply plugin: 'java'

sourceCompatibility = 1.8

repositories {
  mavenCentral()
}

dependencies {
  testCompile group: 'junit', name: 'junit', version: '4.12'
}

intellij {
  version '2017.3.5'
}

intellij {
  plugins 'kotlin'
}

patchPluginXml {
  changeNotes ""
}

The issue I'm running into is the following exception when I'm using KtVisitor:

Caused by: java.lang.ClassNotFoundException: org.jetbrains.kotlin.psi.KtVisitor PluginClassLoader[com.magicbytes.kotlin-converter-plugin, 0.0.1] com.intellij.ide.plugins.cl.PluginClassLoader@7591f7
    at com.intellij.ide.plugins.cl.PluginClassLoader.loadClass(PluginClassLoader.java:63)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 28 mor**

Solution

  • First, you didn't say how did you run the debug IDE. I assumed you're using IDEA build instead of gradle, and my guess was right. Please give clearer descriptions next time.

    Two steps (according to my comments and your reply):

    • Change id 'org.jetbrains.intellij' to your real package name to avoid conflicts with existing IDEA plugins (possibly the IDEA core is using this id).
    • Stop using IDEA build. Instead, use gradle runIde command to start a debug IDE.