My experience building a Jira server plugin for the first time

This will be my first real attempt at creating a plugin for Jira Core (server) :slight_smile:

I am planning to use this topic to track my progress in creating a custom add-on for Jira Core.

The plugin will attempt to:

  1. Create new issue types
  2. Create some custom fields
  3. Add a custom link type
  4. Add a view panel to the main interface to view linked issues (in a more graphical way)
  5. Add a pop-up window with some issue details in the view above

The idea is to create a group of issues that can be displayed on a picture background.

This thread is purely for me to keep track of my progress, but any comments/suggestions/tips/tricks or your own experiences will be appreciated!

Ok, start with the basics…

https://developer.atlassian.com/server/jira/platform/getting-started/

Which suggest that I try the Atlassian SDK plugin tutorial…

https://developer.atlassian.com/server/framework/atlassian-sdk/set-up-the-atlassian-plugin-sdk-and-build-a-project/

Ok, following the setup steps in the SDK tutorial, I have successfully created my environment :+1:

$ atlas-version

ATLAS Version:    6.3.7
ATLAS Home:       /usr/share/atlassian-plugin-sdk-6.3.7
ATLAS Scripts:    /usr/share/atlassian-plugin-sdk-6.3.7/bin
ATLAS Maven Home: /usr/share/atlassian-plugin-sdk-6.3.7/apache-maven-3.2.1
AMPS Version:     6.3.14
--------
Executing: /usr/share/atlassian-plugin-sdk-6.3.7/apache-maven-3.2.1/bin/mvn --version -gs /usr/share/atlassian-plugin-sdk-6.3.7/apache-maven-3.2.1/conf/settings.xml
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256M; support was removed in 8.0
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T17:37:52+00:00)
Maven home: /usr/share/atlassian-plugin-sdk-6.3.7/apache-maven-3.2.1
Java version: 1.8.0_181, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-33-generic", arch: "amd64", family: "unix"

So let’s create our first real plugin…

So far still just following the SDK tutorial steps for creating a plugin…

$atlas-create-plugin
 :
<oops - meant to create a Jira plugin!!> ^C

I meant…

$ atlas-create-jira-plugin
Executing: /usr/share/atlassian-plugin-sdk-6.3.7/apache-maven-3.2.1/bin/mvn com.atlassian.maven.plugins:maven-jira-plugin:6.3.14:create -gs /usr/share/atlassian-plugin-sdk-6.3.7/apache-maven-3.2.1/conf/settings.xml
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256M; support was removed in 8.0
[INFO] Scanning for projects...
[INFO] 
   :
   :
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:21 min
[INFO] Finished at: 2018-09-07T19:21:48+00:00
[INFO] Final Memory: 19M/297M
[INFO] ------------------------------------------------------------------------

Hmmm, now moving away from the tutorial and trying to create my own Issue Type.

After some digging, it looks like I need:

  • IssueTypeManager - to create the new issue, and…
  • AvatarManager - to get the avatar ID which is required when creating a new issue type.

Now how do I get access to these???

Trying the following in MyPluginComponentImple(…):

    :
        IssueTypeManager issueTypeManager = ComponentAccessor.getComponentOfType(IssueTypeManager.class);
        issueTypeManager.createIssueType(name, description, 0L);
    :

Oh no… this causes the following (cryptic) message:

java.lang.IllegalStateException: ComponentAccessor has not been initialised.

This is not expected to occur on a production system. 
Developers that encounter this message within a unit test
should use n MockitoMocksInContainer rule to initialize mockito and ComponentAccessor.
For more detailed explanation read the documentation
for MockComponentWorker in the jira-tests artifact for more information
about what causes this error and how to address it.

I’m sure that is very clear for those who have done this before :slight_smile: - unfortunately I’ve never done this… So I’m assuming we are using Mockito here to mock out the interface, but I’m going to have to try and find an example of how to actually use it…

Also not sure that ComponentAccessor is the right approach - any other ways to do this?

Not sure why you are getting Illigal State Exception when using the Component Accessor, but instead of using the Component Accessor, you could try using Component Imports.

If you created a plugin from atlas-create-jira-plugin (Spring Scanner 1 if im not mistaken), you will need to add component-import plugin modules to your plugin descriptor and then use it in your own class constructor.

Otherwise, you can use Spring scanner 2 which allows the use of Component Import and Autowire / Inject annotations.

1 Like

Thanks for the help Victor :slight_smile:

I am just starting out so would rather use the latest tools - checking out the Spring Scanner 2 examples now to see how to use them…