IntelliJ plugin: maven, gradle and travis-ci

1.1k Views Asked by At

Currently, my built structure for a plugin in is a bit messy: I'm using the normal IDEA project file to build the plugin locally. When I push it to the repo and travis-ci is building it, it uses the maven pom.xml because for travis to work, it always has to download the complete IDEA sources.

Although this works, this has several drawbacks:

  1. I need to keep two built mechanisms up to date. This is
    • When a new IDEA version is out (every few weeks), I need to change the SDK in maven and in my IDEA settings
    • When I add a new library, change resources, etc. I need to do this for two the two settings as well
  2. I ran into problems when I kept the IDEA Maven plugin turned on because it saw the pom.xml and interfered with my local built. Turning it off means, I cannot download libraries with Maven which has the feature of tracking dependencies.

I saw that Gradle has an 'idea' plugin and after googling, I got the impression that Gradle is the preferred choice these days. I have seen Best way to add Gradle support to IntelliJ IDEA and I'm sure I can use the answers there to turn my pom.xml into a valid build.gradle.

However, maybe someone else has already done this or can provide a better approach. What I'm looking for is a unified way to build my plugin locally and on Travis-CI.

Some Details

For compiling an IDEA plugin, you need its SDK which you can access through an installation of IDEA or a download of the complete package. Locally, I'm using my installation for the SDK. With Travis, my maven built has the rule to download the tar.gz and extract it.

1

There are 1 best solutions below

0
halirutan On

It turns out that in particular for building an IntelliJ plugin, Gradle seems to have many advantages. This is mainly due to the great IntelliJ plugin for Gradle which makes compiling plugins so much easier. With Gradle, I could turn my >220 lines of Maven build into a few lines of easily readable Gradle code. The main advantages are that

  1. It takes care of downloading and using the correct IDEA SDK while you only have to specify the IDEA version.
  2. It can publish your plugin to your Jetbrains repository and make it instantly available to all users
  3. It fixes items in your plugin.xml, e.g. you can use one central version number in gradle.build and it will keep plugin.xml up-to-date or it can include change-notes
  4. It seamlessly integrates with Travis-CI

How to use Gradle with an existing IDEA plugin

Do it manually. It's much easier.

  1. Create an empty build.gradle file
  2. Look at an example and read through the README (there are many build.gradle of projects at the end) to see what each intellij property does.
  3. Adapt it to your plugin by
    1. Setting the intellij.version you want to build against
    2. Setting your intellij.pluginName
    3. Define where your sources and resources are
    4. Define your plugin version
    5. Define a Gradle wrapper that enables people (and Travis) to build your plugin without having Gradle
  4. Create the gradle wrapper scripts with gradle wrapper
  5. Test and fix your build process locally with ./gradlew assemble

If everything works well, you can push build.gradle, gradlew, gradlew.bat and the gradle-folder to your repo.

Building with Travis-CI

For Travis you want to use the gradlew script for building. To do so, you need to make it executable in the travis run. An example can be found here.