A Maven project has a fairly rigid layout, always with a top-level XML file named pom.xml made up of the plugins name, version, dependencies and so on. The groupId
and artifactId
variables in pom.xml are what make a plugin unique within Maven. The artifactId
is also what will appear as part of your plugin .jar files name. The name
variable is the more verbose name of the plugin, as seen in the JIRA plugin administration pages. The SDK will create a working pom.xml file for us with some reasonable default values.
Tip
Atlassians guidelines on the use of JIRA are that a name such as Acme plugin for JIRA is okay, whereas JIRA plugin for Acme is not. The former connotes a 3rd party plugin for JIRA, while the latter connotes an Atlassian-developed tool. If in doubt, contact developer-relations@atlassian.com .
The first thing to do is to unpack the SDK in a convenient location. This location is referred to as $SDK_HOME
in the examples below. You can then create a JIRA plugin with a single command:
$SDK_HOME/bin/atlas-create-jira-plugin
This command will prompt you for a few values and then create a new plugin directory with enough files to build a plugin. This skeleton plugin does nothing, but it can be installed in JIRA and will appear in the list of plugins shown in the Administration plugins page.
As mentioned earlier, the artifactId
and groupId
values appear directly in the Maven pom.xml file. Every Atlassian plugin has a unique identifier named key . The key for each plugin is defined in the file atlassian-plugin.xml, and by default the key is artifactId
.groupId
.
The version
argument is the version of your plugin, not the JIRA version. Versions can be any text but the Atlassian Plugin Exchange (see the section ) now requires that the version starts with three digits, not two. A version can also look like 4.2.0-alpha
. The package
argument is the name of the Java package that the plugins Java source code will use.
Tip
If you want to, you can also provide the same information that was required to create a plugin directly from the command line:
$SDK_HOME/bin/atlas-create-jira-plugin \ --artifactId myplugin \ --groupId com.mycompany.jira.plugins \ --version 4.2.0 \ --package com.mycompany.jira.plugins.myplugin --non-interactive
Important Plugin Files
The most important files in a plugin directory and their purposes are as follows.
pom.xmlThe top-level Maven 2 project file for the plugin.
READMEThe place to start for the description of what the plugin is intended to do.
LICENSEA place holder for the license for the plugin. Many JIRA plugins use the BSD license by default, but the section has more information about choosing a license.
srcThe directory that contains all the source files needed to build the plugin.
src/main/resources/atlassian-plugin.xmlThe XML file that specifies exactly what the plugin really contains. The order of the elements in this file doesnt make a difference to how they work.
src/main/java/com/mycompany/jira/plugins/mypluginThe default location for Java source files, based on the package
name used when the plugin was created.
src/main/java/com/mycompany/jira/plugins/myplugin/MyPlugin.javaA sample Java source file, automatically generated. You can rename or delete this file later on.
targetThe location of all generated files after a build has finished. None of the files in this directory need to be version controlled.
target/myplugin-4.2.0.jarThe generated plugin package that is deployed to JIRA to actually use the plugin.
There are a few other files generated in the src/test directory related to testing your plugin. You can delete them if theyre not wanted, but an even better practice is to write some tests as described at http://confluence.atlassian.com/display/DEVNET/Plugin+Testing+Resources+and+Discussion.
Reading a Plugin
Before diving into building a plugin, its useful to know how to understand what any JIRA plugin does. Knowing how to read a plugin also makes it easier to find examples on which to base your own work.
My own approach is to start with the top-level Maven file pom.xml and to look for the jira.version
element. That should tell you which version of JIRA the plugin was last built against. If its too old for you to use, then see for ideas on how to update it. There is also a jira.data.version
element that tells you the version of the JIRA database schema the plugin last worked with. As might be expected, this changes less frequently than jira.version
.
The next file to read is src/main/resources/atlassian-plugin.xml. This file contains all the different plugin module types that are used in the plugin and tells you what the plugin provides; e.g., a new custom field type. The initial skeleton plugin doesnt have any plugin modules in this file because it doesnt do anything.
Then Ill read any documentation or perhaps look at a few screen shots. Usually only after all that do I look at actual Java source code and Velocity template files.
Building and Deploying a Plugin
The minimal commands to build a plugin from the command line are:
$ cd myplugin$ $SDK_HOME/bin/atlas-package...[INFO] ----------------------------------------------------[INFO] BUILD SUCCESSFUL[INFO] ----------------------------------------------------[INFO] Total time: 26 seconds[INFO] Finished at: Wed May 11 03:11:48 PDT 2011[INFO] Final Memory: 56M/118M[INFO] ----------------------------------------------------