12

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?

Owen
  • 38,836
  • 14
  • 95
  • 125
  • What do you mean by, "this information never seems to get passed along to the generated JAR"? What are you seeing? What errors are you getting? – Software Engineer Jun 10 '14 at 18:35
  • The [documented structure of the plugin jar](http://confluence.jetbrains.com/display/IDEADEV/IntelliJ+IDEA+Plugin+Structure) does not provide any way to specify a library dependency in the jar. I'm hoping that there's some other way to do it (maybe something clever involving a plugin dependency). – Owen Jun 10 '14 at 18:38
  • A five second web-search returned this, which is I think pretty close to what you're doing: http://confluence.jetbrains.com/display/SCA/Developing+IDEA+plugin+with+dependency+on+Scala+plugin – Software Engineer Jun 10 '14 at 18:41
  • Hm, it's sort of related, but I really don't want to depend on the Scala plugin, but only on the Scala library. – Owen Jun 10 '14 at 18:42
  • Well, at the moment I'm actually using SBT, but, yes, the library is retrieved from a Maven repository in the same manner as Maven would. But, using actual Maven is an option. – Owen Jun 10 '14 at 18:45
  • Then this SO question may help: http://stackoverflow.com/questions/11492301/how-does-intellij-idea-manage-plugin-dependencies -- this means that you must have the dependency listed as a provided dependency in maven (or the equivalent in intellij's project structure), and have the lib deployed to the lib directory under intellij's home lib. – Software Engineer Jun 10 '14 at 18:45

2 Answers2

7

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.

Dany
  • 1,490
  • 1
  • 12
  • 22
6

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"
}
breandan
  • 1,965
  • 26
  • 45