NoClassDefFoundException in runIde gradle task

Answered

Hi Everybody, 

I wrote an Intellij Ide plugin and added several classes as dependency to the project: 

build.gradle: 

dependencies {

implementation project(":model")
implementation project(":code-annotation-metainfo-lib")
}

settings.gradle: 

include ':model', ':code-annotation-metainfo-lib'
project(':model').projectDir = new File("../../code-annotation-metainfo-lib/model")
project(':code-annotation-metainfo-lib').projectDir = new File("../../code-annotation-metainfo-lib/code-annotation-metainfo-lib")

the 'code-annotation-metainfo-lib' contains the class MetaInfoAPIImpl that gets initialized in one of the classes of my plugin. 
When I try to run die plugin either by the gradle 'runIde' task or directly installing it from disk I get the error message: 

Caused by: java.lang.NoClassDefFoundError: Could not initialize class communication.MetaInfoAPIImpl

There are a few other errors but ultimately I figured they are all caused by this one. 

My question is, do Intellij plugin have general problem with dependencies added like this or is my problem something else? 

 

5 comments
Comment actions Permalink

Hi Daniel,

It's hard to tell the reason as it all depends on what is the final artifact structure. Are your classes bundled into JAR and included in the ZIP distribution file? It'd be good if you shared your final plugin ZIP structure.

0
Comment actions Permalink

hi thanks for the reply.

how can I look up the build artifact of the 'runIde' gradle task? 

 

as for if they are bundled into the jar. I dont know i kinda hoped for that gradle would take care of that. 

there are no other settings i have done in the gradle.build file only the ones shown above  so if those don't take care of jar bundeling it doesn't happen.  
can you tell me how i can tell gradle to jar pack them and include those jars.

0
Comment actions Permalink

Hi Daniel,

Sorry, but I don't understand your project structure, and it sounds like a general Gradle usage issue.

If you create JARs of dependent projects, you must configure the build script to include JARs in the "lib" directory in the plugin ZIP (it should also land in the "build/idea-sandbox/plugins/your-plugin/lib" directory for the runIde and similar tasks). In general, Gradle IntelliJ Plugin bundles implementation dependencies JARs in the "lib" directory.

I suggest taking a look at Gradle IntelliJ Plugin usage examples:

https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin-examples.html

Try to find something that uses a similar structure (https://github.com/SonarSource/sonarlint-intellij look similar at first sight) and identify why it doesn't work in your case.

0
Comment actions Permalink

Ok so after some debugging I figured out that the error originates in my persistance management. To establish a connection with the database i need two files: for one the persitsance.xml and an .env file both located in the resource folder.

When i start the project as intellij plugin it isn't able to read those two. 

I checked the working directory which gets set to some obscure bin file. So my question is how can i tell my connector to get the files from the resource folder?

0
Comment actions Permalink

If you put the "persistence.xml" file into the "resources" folder, then you should be able to retrieve them with e.g. YourClass.class.getClassLoader().getResource("persistence.xml") when the plugin is run.

Without more details, it's hard to help you. What does it mean that files cannot be read? Is there any error? Are the files packed in the JAR? What obscure bin file do you mean?

0

Please sign in to leave a comment.