Introduction to Jira Plugin Development

Welcome to the world of Jira plugin development, where the possibilities are endless, and the complexity can be daunting. But fear not, dear developer, for this guide is here to walk you through the process of creating Jira plugins using Java, with a dash of humor and a whole lot of practical advice.

Why Java?

Jira’s core language is Java, and if you’re aiming to develop plugins for Jira Server or Data Center, Java is your best bet. The Atlassian SDK, which is the primary tool for developing these plugins, is heavily centered around Java.

Setting Up Your Environment

Before you dive into the nitty-gritty of plugin development, you need to set up your environment. Here’s a step-by-step guide to get you started:

Installing the Atlassian SDK

To develop plugins for Jira Server or Data Center, you’ll need the Atlassian SDK. Here’s how you can install it:

curl -O https://marketplace.atlassian.com/download/plugins/jira/atlassian-plugin-sdk/version/8
tar -xvf atlassian-plugin-sdk-8.x.x.tar.gz
cd atlassian-plugin-sdk-8.x.x

Creating a New Plugin

Once you have the SDK installed, you can create a new plugin using the following command:

atlas-create-jira-plugin

This command will prompt you for several details, such as the plugin name, group ID, and version. Here’s an example of what the interaction might look like:

Define value for 'groupId': com.example.myplugin
Define value for 'artifactId': my-jira-plugin
Define value for 'version': 1.0-SNAPSHOT
Define value for 'package': com.example.myplugin

Understanding the Plugin Descriptor

The heart of any Jira plugin is the atlassian-plugin.xml file. This file acts as the descriptor for your plugin, telling Jira what your plugin does and how it integrates with the system.

Here’s an example of what this file might look like:

<atlassian-plugin key="com.example.myplugin" name="My Jira Plugin">
    <plugin-info>
        <description>This is my first Jira plugin.</description>
        <vendor-name>Maxim Zhirnov</vendor-name>
        <vendor-url>https://example.com</vendor-url>
    </plugin-info>
    <!-- Add your plugin modules here -->
    <customfield-type key="my-custom-field" name="My Custom Field" class="com.example.myplugin.MyCustomField">
        <description>The My Custom Field Plugin</description>
        <resource type="velocity" name="view" location="/templates/customfield/view.vm"/>
        <resource type="velocity" name="edit" location="/templates/customfield/edit.vm"/>
    </customfield-type>
</atlassian-plugin>

Building and Deploying Your Plugin

Building the Plugin

To build your plugin, navigate to your plugin directory and run the following command:

atlas-compile
atlas-package

This will compile your code and package it into a JAR file.

Deploying the Plugin

To deploy your plugin, you need to upload the JAR file to your Jira instance. Here’s how you can do it:

  1. Log in to your Jira instance as an administrator.
  2. Go to the “Manage Apps” section.
  3. Click on “Upload App” and select your JAR file.
  4. Follow the prompts to complete the installation.

Using Forge for Jira Cloud

If you’re developing plugins for Jira Cloud, the game changes slightly. You’ll need to use Atlassian’s Forge platform, which supports a broader range of programming languages, including JavaScript and Node.js.

Setting Up Forge

To get started with Forge, you’ll need to install the Forge CLI:

npm install -g @forge/cli
forge login

Creating a New Forge App

Here’s how you can create a new Forge app:

forge create

Follow the prompts to set up your app. Here’s an example of what the interaction might look like:

? What is the name of your app? My Jira Cloud App
? What is the description of your app? This is my first Jira Cloud app.
? Which products does your app integrate with? Jira

Writing Custom UI Extensions

Forge allows you to create custom UI extensions using JavaScript and Forge UI components. Here’s an example of how you might create a simple UI extension:

import { render, html } from '@forge/ui';

const App = () => {
  return html`
    <section>
      <h1>Welcome to My Jira Cloud App!</h1>
    </section>
  `;
};

export const run = render(<App />);

Using Java with Forge

While Forge is primarily designed for JavaScript and Node.js, you can still use Java for the backend logic. Here’s how you can integrate Java with Forge:

Setting Up the Backend

You can use the Atlassian Connect framework to create RESTful endpoints in Java. Here’s an example of how you might set this up:

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/my-endpoint")
public class MyEndpoint {
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String getHello() {
        return "Hello from Java!";
    }
}

Calling the Backend from Forge

You can then call this endpoint from your Forge app:

import { api, context } from '@forge/api';

const fetchHello = async () => {
  const response = await api.asApp().requestJira(`rest/my-endpoint`, {
    method: 'GET',
  });
  const hello = await response.json();
  return hello;
};

const App = () => {
  const [hello, setHello] = useState('');

  useEffect(() => {
    fetchHello().then(setHello);
  }, []);

  return html`
    <section>
      <h1>${hello}</h1>
    </section>
  `;
};

export const run = render(<App />);

Diagram: Plugin Development Workflow

Here’s a flowchart to help you visualize the plugin development workflow:

graph TD A("Install Atlassian SDK") -->|Install SDK| B("Create New Plugin") B -->|Create Plugin| C("Define Plugin Descriptor") C -->|Define Descriptor| D("Build Plugin") D -->|Build| E("Deploy Plugin") E -->|Deploy| F("Test Plugin") B("Install Forge CLI") -->|Install CLI| H("Create New Forge App") H -->|Create App| I("Write Custom UI Extensions") I -->|Write Extensions| J("Integrate Java Backend") J -->|Integrate Backend| K("Deploy Forge App") K -->|Deploy| L("Test Forge App") F -->|Test Server Plugin| M("Success") L -->|Test Cloud Plugin| C("Success")

Conclusion

Developing Jira plugins can be a complex but rewarding experience. Whether you’re working with Jira Server, Data Center, or Cloud, understanding the tools and frameworks available to you is key. With this guide, you should now have a solid foundation to start building your own Jira plugins, whether you’re using Java for server-side development or leveraging Forge for cloud-based apps.

Remember, practice makes perfect, so don’t be afraid to experiment and push the boundaries of what you can achieve with Jira plugins. Happy coding