Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify library dependencies for an IntelliJ IDEA plugin?

I am developing a plugin for IntelliJ IDEA. The way I am going about this is by creating a plugin project in IDEA, then packaging this into a jar with appropriate META-INF/plugin.xml, and installing the plugin from the jar.

The problem is that I would like to add a dependency on org.scala-lang:scala-library:2.11.0. I have this specified as a library dependency in the IDEA project, but this information never seems to get passed along to the generated JAR.

How can I include this information in such a way that IntelliJ IDEA will recognize it?

like image 376
Owen Avatar asked Jun 07 '14 22:06

Owen


People also ask

How do I manually add dependencies in IntelliJ?

Press Alt+Insert to open the Generate context menu. From the context menu, select Add dependency. In the Dependencies tool window, in the search field, start typing the name of your dependency. In the list of results select the one you need and click Add.

How do I change dependencies in IntelliJ?

From the main menu, select File | Project Structure Ctrl+Alt+Shift+S , and go to Modules | Dependencies. In the next dialog, click Edit, and then click Configure next to the Include transitive dependencies option. Select the dependencies you want to include in the library and click OK.

How do I re import Maven dependencies in IntelliJ?

Reload a Maven project If you want to control the importing process of your project, you can manually trigger the action. In the Maven tool window, right-click a linked project. On invoking this action, IntelliJ IDEA parses the project structure in the Maven tool window.


2 Answers

As far as I understand, you want to bundle some library (e.g. scala library) with your plugin. This is pretty simple.

  1. Go to Project Settings, select module and go to Dependencies tab. Set scope for the library you want to bundle to 'Compile'. In this example it is 'checker-framework' library. 'groovy-2.3.6' library will not be bundled due to its scope set to 'Provided'. Save changes.

    Module dependencies tab

  2. Prepare plugin for deployment

    Prepare plugins for deployment action

  3. Then you got plugin, zipped, ready for deployment (uploading to repo or installing locally) in the root of project. It will contain lib folder with all necessary jars.

like image 84
Dany Avatar answered Oct 03 '22 03:10

Dany


The officially supported plugin dependency management solution is to use Gradle with the gradle-intellij-plugin, via Gradle's dependencies or the intellij.plugins entry points. If you want to add a dependency on an artifact (ex. hosted on Maven Central), then configure dependencies just as you normally would in a Gradle based project:

buildscript {
    repositories {
        mavenCentral()
    }
}

dependencies {
    compile("org.scala-lang:scala-library:2.11.0")
}

The intellij.plugins entry point will add an artifact in the current project, as well as a <depends> tag to your plugin.xml file. To install an external plugin alongside your own, for example if you are using the Plugin Extensions feature (suppose the plugin is hosted on the JetBrains Plugin Repository), use the following snippet:

plugins {
    id "org.jetbrains.intellij" version "0.2.13"
}

intellij {
    //...
    plugins "org.intellij.scala:2017.2.638"
}
like image 42
breandan Avatar answered Oct 03 '22 02:10

breandan