Java functionality extracted as a plugin

Matt Ellis

In the latest EAP build of IntelliJ IDEA 2019.2 we’ve extracted Java functionality into a separate plugin. This separates the Java implementation from the “platform” part of IntelliJ IDEA and introduces some flexibility for the future. For example, we could include Java functionality as a plugin to other products, and other plugins such as Gradle can now take optional dependencies on Java, and still work if Java isn’t available.

The new plugin is not visible in Settings | Plugins and cannot be switched off, so there should be no impact on end users. However, if you’re writing a plugin for IntelliJ IDEA you may need to make some small changes to continue working correctly.

Firstly, if your plugin depends on the Java part of the IntelliJ API, you will need to declare this dependency in your plugin.xml file, by adding the following line:

<depends>com.intellij.modules.java</depends>

You might have this line in your plugin.xml already, as this is the recommended way of declaring a dependency on the Java functionality, even for earlier versions of IntelliJ IDEA. However, it is now required, to ensure that your plugin can access classes from the Java plugin at runtime. See the Plugin Compatibility with IntelliJ Platform Products page for more details on dependencies.

Secondly, if you’re developing a plugin using gradle-intellij-plugin, you need to tell Gradle about the Java plugin. Add the following to build.gradle in order to include classes from the Java plugin into the compilation classpath, and tell the IDE to load the plugin at runtime:

intellij {
  plugins 'java'
  // ...
}

Please let us know if you have any issues.

Comments below can no longer be edited.

9 Responses to Java functionality extracted as a plugin

  1. Sergey Patrikeev says:

    June 14, 2019

    Please note that if you use `gradle-intellij-plugin` and IDE build used to compile your plugin is prior to 2019.2, adding `intellij { plugins ‘java’ }` in `build.gradle` will not work because older IDEs did not have Java plugin. So you will need to update `intellij.version` value to 2019.2 or higher

  2. Mariano de Achaval says:

    August 7, 2019

    How do we build a plugin that works for new and old intellij versions if we need to have this property

    • Sergey Patrikeev says:

      August 8, 2019

      In this case you have to declare dependency in `plugin.xml`:
      `com.intellij.modules.java`
      this module is available both in old and new IntelliJ versions.

      If you compile your plugin against IDE prior to 192, no additional steps are required, because Java plugin’s classes will be available in class-path of your plugin by default, since they were part of the platform jars.

      But if you compile your plugin against 192+ and use `gradle-intellij-plugin`, it is necessary to add `intellij { plugins ‘java’ }` to `build.gradle` to make Gradle add Java-plugin (now separated jars) to the class-path, otherwise your plugin will not compile. Note that this is required only to build the plugin. It will perfectly work in old IDEs if “ allows so.

      • Sergey Patrikeev says:

        August 8, 2019

        *** if “since-build” allows so.

  3. Luke Imhoff says:

    August 15, 2019

    This also affects usage of the JPS builder system if you’re using that for building projects.

  4. Joachim Beckers says:

    September 15, 2019

    For build.gradle.kts, this would be the change needed:

    intellij {
    setPlugins(“java”)
    }

  5. Ayeb Umada says:

    December 26, 2019

    I am getting the following error after adding intellij { plugins ‘java’ } in Build.gradle.

    – Could not find method intellij() for arguments [build_6rvi6p1reorgm6pzfxbdij6or$_run_closure3@36fc6d29] on root project ‘oem-content-workspace’ of type org.gradle.api.Project.

    What should I do now?

  6. Rimac Valdez says:

    January 11, 2020

    Is it also necessary to add something for c++ support?

    Something like this maybe?
    intellij {
    plugins ‘c++’ // or maybe cidr?
    // …
    }

    • Matt Ellis says:

      January 17, 2020

      There should be no need to add a plugin for C++, since C++ isn’t available as a plugin to IntelliJ. Instead, you need to make sure your `intellij.type` is set to `CL` or `AC` to create a plugin for CLion or AppCode respectively. This should mean that the C++ modules are referenced correctly for compilation.

      You’ll also need to add a line to your plugin.xml for runtime compatibility:

      `<depends>com.intellij.modules.cidr.lang</depends>`

Subscribe

Subscribe for updates