How to Compile Spigot Plugins

December 10, 2015

Compiling a plugin for a Minecraft server was difficult enough for the novice before the implosion of the Bukkit project. In a world without precompiled jars and with documentation scattered around more, how does one compile a Spigot/Bukkit plugin from GitHub or even make their own?

This brief guide will focus on compiling both Spigot itself and existing plugins, with the process of setting up an IDE and diving into plugin development being beyond the scope of this article.

A prerequisite to compiling a plugin for Spigot is to compile Spigot itself. And to do that, you’ll need a few tools…

Spigot BuildTools

Spigot’s BuildTools.jar is an all-in-one tool that will automatically download all of Spigot’s dependencies, compile it for your use, and save a copy into your system’s Maven repository so you can compile plugins against it.

Before you can use BuildTools, you must have the following installed:

  • Git — A source control tool that BuildTools needs to talk to remote repositories
  • Java JDK — You probably have a Java Runtime Environment, but you may not have a Java Development Kit

You’ll find instructions for Windows, OS X and Linux on the BuildTools wiki page. Follow the instructions for your platform and you should be up and running quickly. If all goes well, you should be able to execute this command in a terminal window (in the same directory as BuildTools.jar):

java -jar BuildTools.jar --rev latest

The window will be spammed with lines of text as it downloads and compiles everything, but it will inform you of its success after a few minutes of working. When it’s complete, the folder containing BuildTools should have a shiny new file named something along the lines of spigot-1.8.8.jar. BuildTools should also install Maven and load the local repository with the relevant jars needed to compile a plugin.

That Spigot jar can now be used to run a server.

Compiling a Plugin

Suppose you find a plugin you really want to use on your server…the source code is all freely available on GitHub, but the developer didn’t compile a jar for you to use. Now what?

Assuming you’ve successfully set up and run BuildTools, you now have everything you need to compile it yourself. Let’s use my simple SignText plugin as an example.

Grab a copy of the source, either by downloading it as a ZIP file or by using Git.

git clone https://github.com/redwallhp/SignText.git
cd SignText

If you look inside, you’ll see something like this:

▸ src/main
▸ .gitignore
▸ LICENSE.md
▸ README.md
▸ pom.xml

That pom.xml file right there means this plugin uses Maven as its build system, like the majority of plugins with public source.

If you open the file, you should see a bunch of XML tags, with this part being the important bit:

<dependencies>
   <dependency>
       <groupId>org.bukkit</groupId>
       <artifactId>bukkit</artifactId>
       <version>1.7.9-R0.2</version>
       <type>jar</type>
       <scope>provided</scope>
   </dependency>
</dependencies>

Before you attempt to compile, you just need to double check that you’re compiling against an API version that you actually have installed. As you can see, this plugin is using version 1.7.9-R0.2 of the Bukkit API. But we’ve compiled Spigot 1.8.8, which implements Bukkit API version 1.8.7-R0.1-SNAPSHOT. This means your options are to compile an older version of Spigot and the Bukkit API with BuildTools—which you can’t do for pre-1.8 versions anymore—or to simply update the plugin.

As SignText is a simple plugin, you can just replace the version in pom.xml and you should be good to go. Some complicated plugins that reference version-specific things won’t work if you do this, but many will. So let’s do that now…

With the version changed to match the Bukkit API version we have, we make sure we have a terminal window opened to the folder where the pom.xml file is and execute the following command:

mvn clean package

If all goes well, you should see “BUILD SUCCESS” when it finishes. If it works, check the target/ folder for a shiny new jar. Congratulations, you’ve just compiled your first plugin.