Developers have many reasons to create plugins for IntelliJ — maybe to add some custom functionality, change some core functions or automate workflows. Whatever the reason may be, it is an incredibly useful skill to have complete control over your development environment and to tailor it to your (or your development teams) needs.
This is the introduction to a series that should kick start your development for IntelliJ plugins, where we’ll cover the primary concepts for the IntelliJ platform, as well as Kotlin development for the UI. Plugins can be written in Java or Kotlin, however for the purposes of demonstration, I will primarily use Java. The only assumed knowledge will be a good foundation of Java and GitHub.
Creating the project
First of all, you should install the latest version of IntelliJ (as of writing, the latest version is 2020.3.2) as we’ll be using it to develop the plugin. As default, IntelliJ bundles the
Plugin DevKit with default installation, however this approach is discouraged by JetBrains, and all future plugins should use the
gradle-intellij-plugin. Once installed, I also recommend cloning the IntelliJ Community source code so if you see some functionality within IntelliJ that you would like to replicate in your own plugin, you can see how it was originally accomplished. The repository for the IntelliJ Community edition can be found at https://github.com/JetBrains/intellij-community.
After installing IntelliJ, go to https://github.com/JordanGibson/ PluginTemplate and click “Use this template”. This is some boilerplate code I have provided to ease a lot of the setup. After clicking “Use this template”, it will ask you to create your own repository, which you can then clone inside of IntelliJ.
Testing the plugin
After opening the project in IntelliJ, to test that everything is working as expected, we’ll run the plugin which is supplied with the template. Start off by opening the project from the directory which it was cloned to. The gradle project may take 10–15 minutes to import as it redownloads the intellij-community source. The version of IntelliJ which this plugin is built for is 2020.2.3, but any IntelliJ version above 2020.1 should be fine. Once the project is loaded, change the build configuration (in the top right) to Test Plugin.
This build configuration will start a fresh instance of the ide, with the plugin installed. Press the run button, and the project will begin building. The first run of the plugin usually takes significantly longer than the following builds. Once the build is complete, you will then see a fresh install of IntelliJ pop-up, as below. This is the sandbox (or debug) instance of IntelliJ which we will use to test the plugin.
Once this window appears, create a new Java project (the configuration of this project doesn’t matter as we won’t be running the project).
Note: You can open an existing project if the plugin is project specific, however IntelliJ will have to index the project, which can take a lot of time depending on the project size which can be frustrating if it is required on every launch of the ide.
After the new project is created, you should be presented with a blank ide screen.
Once at this stage (and IntelliJ isn’t performing any background tasks), click
Tools and the first option should be a new option, called
When clicking on this option, a balloon dialog should appear in the bottom right corner of the screen, displaying
Hello world! as below.
Well done! You’ve just completed the first step in creating your own plugin (and got most of the boring stuff out of the way). In the first episode, I will go into more depth about understanding the code we just executed, and changing the functionality.
When you’re ready, move on to Episode #1 — Understand and modifying your first action.
Thanks for reading!