mysqlintellij-ideaplugins

Using mysqlconnector with an IntelliJ Plugin


I am hoping you might be able to help me with an issue that I can not manage to find a solution for. I want to build an IntelliJ Plugin that is able to connect to a mysql database. However, adding the mysql connector jar as a library like you would for a simple project does not seem to work and I am out of ways to try it to work. Do you have any suggestions I might try? I thought about the plugin.xml dependencies but I can not seem to find a way to specify the dependency properly. Any hint would be much appreciated.

Here is what I have tried:

In a plugin project, I added the mysql connector as dependency:

dependency setup

I have a DB connection class:

connection class

And another class where I've added my main method and I want to execute an SQL query:

execution result

As seen, I am getting a ClassNotFound exception for the Driver.

If I do the exact same setup, but on a simple Java project, the connection runs with no issues. See below:

dependency setup result

There is a warning about the deprecated explicit loading of the Diver but this is not the issue. Even iv I remove this, the plugin project still can not find the class.


Solution

  • Actually it seems like the recommended way of declaring dependencies for the Plugins is via Gradle dependencies. Comment by Jakub here https://www.youtube.com/watch?v=-6D5-xEaYig&lc=UgzA2TPtX_1H2PaL7Q54AaABAg.9Mv96dstxEG9N20UT7YuRQ I looked up how to declare mysql as gradle dependency and found this: https://www.reddit.com/r/gradle/comments/apme5g/how_to_add_mysqlconnector_to_gradle_build/

    So I used

    dependencies {
        implementation ("mysql:mysql-connector-java:8.0.24")
    }
    

    in build.gradle and all works fine now :) Hope this will help others as well.