Creating a plugin with Maven using IntelliJ IDEA

Dec 9, 2021
Creating a plugin with Maven using IntelliJ IDEA
  • Creating a blank Spigot plugin

    Using Maven in the IntelliJ IDE

    Maven is a software project management and comprehension tool, as Apache, the creators of Maven say it.
    The main objective of Maven is to make the build process easier. And that's exactly what we want.

    In this tutorial you are going to learn how to create a Spigot plugin using Maven in IntelliJ IDEA.


    • We will be using the IntelliJ IDEA IDE to develop our plugin.
    • You will also need the Java Developer Kit (JDK)
    • Because we use Maven you need a domain name. If you don't have one you can also use your github profile or your email as mentioned below.
    • Some basic Java knowledge. If you already know how to program take a look at the Crash Course to Java in our Wiki or Oracle's Nuts and Bolts overview.

    Creating a new project(top)

    If you start IntelliJIDEA for the first time, you'll see something like this:


    Click "Create New Project". If you've already opened InteliJ IDEA before, click File ->
    On the left side, click Maven, then click on the dropdown menu called "Project SDK". Navigate to where you have JDK installed. Click "Next".

    Now, you need your domain name. Don't use a domain you don't own!
    At GroupId fill in your domain name, but inverted. In my case would be nl.codingtime.
    If you use GitHub it would be io.github.[username]. If you use your email, [yourname] would be[yourname].

    Your ArtifactId is the name of your plugin. In this case TutorialPlugin. If you had a plugin called MyAwesomePlugin the ArtifactId would be MyAwesomePlugin, of course.


    This is what the screen should look like! Hit that next button. We can almost start programming, but there are a few more things to do. Now you can change the project name but that's not necessary. Assuming that you don't want your project to be in a random folder, change the project location to a place where you want your project to be saved.

    Now press the Finish button!

    Setting up the pom.xml(top)

    POM stands for Project Object Model. That's where we add our dependencies and other stuff.

    You can see it on your screen now. To tell Maven that we make a Spigot plugin and want to use the API for that, we need to add a few things to the pom.xml file. We need to tell Maven where to get the API from, and then we need to tell Maven that our plugin depends on the Spigot API. Do that by copy-pasting this into your pom.xml:
    Code (XML):

    Of course you can change the version of the API. A plugin made with the 1.12.2 API would have a version of 1.12.2-R0.1-SNAPSHOT, 1.13.2 API 1.13.2-R0.1-SNAPSHOT and so on. However, there are be some differences to the newer APIs that you have to be aware off.

    Here is a correct example:


    Finally, we need to load the Maven changes so they are in effect.
    In IntelliJ IDEA, this can be done by pressing the icon that appears on the right side:
    At your choice, you can enable auto-importing so you don't have to manually load the changes - see here for a short guide.

    Creating the main plugin class(top)

    On the left side, uncollapse "TutorialPlugin" or whatever name you've chosen. Navigate all the way to TutorialPlugin -> src -> main -> java. Right-click java -> New -> Package. As the package name use your inverted domain + your plugin name. In the TutorialPlugin's case that would be nl.codingtime.tutorialplugin. On the left right-click your new package and click New -> Java Class.
    In the pop-up screen fill in a name. Fill in your plugin name e.g. TutorialPlugin. Theoretically you can choose what you want but in this tutorial we're going for the plugin name. This is what the screen looks like:


    Note that you may not use capitals in your package name. Some images are wrong!

    Click OK.
    Now we can start programming!

    Your Main class must extend JavaPlugin. So, instead of:
    Code (Java):
    public class TutorialPlugin {
    Code (Java):
    public class TutorialPlugin extends JavaPlugin {
    IntelliJ IDEA will suggest the JavaPlugin class once you start typing the name, press ENTER to automatically complete the name of the class. This will also automatically add the required import (import Auto completion is an extremely useful features of IntelliJ and you should try to use it wherever possible.
    You can also add required imports for classes after typing them completely by pressing ALT+ENTER on the class name giving the error. IntelliJ will suggest methods to solve the issue, in this case you want to import the class.

    Now let's create our first two methods: onEnable() and onDisable(). These aren't required since they're already in the JavaPlugin object, although some people say that. Let's send a message to the console when these methods are called which we'll do with Bukkit's Logger:
    Code (Java):
    public class TutorialPlugin extends JavaPlugin {
        public void onEnable() {
            getLogger().info("onEnable is called!");
        public void onDisable() {
            getLogger().info("onDisable is called!");
    We can add much more than we did now, but first we're going to create a plugin.yml file.

    Creating plugin.yml(top)

    We can almost compile our plugin, but first we need one more file, called plugin.yml. That file introduces our plugin to Spigot by giving it information about the plugin, such as its name, version, description, and so on.

    On the left right-click Resources -> New -> File.
    In the pop-up screen fill in "plugin.yml" as the file name.


    Click OK.

    There are some things Spigot needs to know:

    1. The plugin name (name: 'CoolPlugin')
    2. The plugin version (version: '1.0.0')
      • Click here to read about semantic versioning.
    3. The path to the Main class (me.person.coolplugin.CoolPlugin)
    4. The api-version that your plugin should use api-version: '1.17'
      • You can only set this to 1.13, 1.14, 1.15, 1.16, 1.17 and any newer API versions.
      • For example, if you imported Spigot 1.17 in your pom.xml file, use api-version: '1.17'.
      • Your plugin can run without this being set although servers will receive a warning in their console about it.
    This is what it can look like:


    Version could also be anything, but since this is our first build we start at 1.0. We could also start with 1.16.0 since we made it for 1.16. If Minecraft and Spigot update to 1.17, our new version is 1.17. For this tutorial, we just start at 1.0.

    For more information on the possible values that the plugin.yml can include take a look at the overview on the Bukkit Wiki.


    It's time to compile our plugin! This will generate a usable JAR file which you can put in your plugins folder and run. :)

    Look to the right side of your IDE window, you should see a tab labeled "Maven". Expand it, then click the drop down next to your plugin's name and expand the Life-cycle tree. Now just double-click "package" and your plugin will be compiled and packaged, all ready to distribute and run on your server.


    You can find the compiled jar file under your project root in a folder named "target".

    You're done! You can run your server and your plugin will tell you that the onEnable method is called, as we have made in the onEnable() method.

  • Loading...
  • Loading...