How to add a custom jar in a Jira Plugin?

Hi hi,

I create an external project, it called JiraCompatibility -> package to a jar. Inside this jar, it has the interface com.mgmtp.jira.app.jiracompatibility.api.JiraCompatibility
And try to use it as a dependency for my Jira Plugin

I following these step:

  1. Package JiraCompatibility as a jar file
  2. Push JiraCompatibility jar file in local repo
  3. Add a dependency in my Jira Plugin
<dependency>
      <groupId>com.mgmtp.jira.app.jiracompatibility</groupId>
      <artifactId>jira-compatibility-core</artifactId>
      <version>1.0.0</version>
      <scope>compile</scope>
    </dependency>

and change the configuration add

<build>
    <plugins>
      <plugin>
        <groupId>com.atlassian.maven.plugins</groupId>
        <artifactId>jira-maven-plugin</artifactId>
        <version>${amps.version}</version>
        <extensions>true</extensions>
        <configuration>
          <extractDependencies>false</extractDependencies>
          ...
        </configuration>
      </plugin>
   ...
  1. I try to run my Plugin with command atlas-debug

But the plugin is disabled. Before adding that dependency my plugin works as normal.
I got this log

2020-05-20 11:19:42,492+0700 plugin-transaction-0 INFO [c.a.jira.plugin.PluginTransactionListener] [plugin-transaction] numberStartEvents:591, numberEndEvents:591, numberSendEvents:376, numberEventsInTransactions:12013, numberOfPluginEnableEvents:282
2020-05-20 11:20:19,409+0700 Spring DM Context Creation Timer WARN [o.e.g.b.e.i.dependencies.startup.DependencyWaiterApplicationContextExecutor] Timeout occurred before finding service dependencies for [NonValidatingOsgiBundleXmlApplicationContext(bundle=com.mgmtp.jira.app.smart-panels-app, config=osgibundle:/META-INF/spring/.xml)]
2020-05-20 11:20:19,411+0700 Spring DM Context Creation Timer WARN [c.a.jira.diagnostic.PluginDiagnostics] Creating a thread and heap dump because Plugin com.mgmtp.jira.app.smart-panels-app failed
2020-05-20 11:20:26,667+0700 Spring DM Context Creation Timer ERROR [c.a.p.osgi.factory.OsgiPlugin] Plugin ‘com.mgmtp.jira.app.smart-panels-app’ never resolved service ‘&jiraCompatibility’ with filter ‘(&(objectClass=com.mgmtp.jira.app.jiracompatibility.api.JiraCompatibility)(objectClass=com.mgmtp.jira.app.jiracompatibility.api.JiraCompatibility))’
2020-05-20 11:20:26,743+0700 Spring DM Context Creation Timer ERROR [c.a.p.osgi.factory.OsgiPlugin] Unable to start the plugin container for plugin ‘com.mgmtp.jira.app.smart-panels-app’
org.springframework.context.ApplicationContextException: Application context initialization for ‘com.mgmtp.jira.app.smart-panels-app’ has timed out waiting for (&(objectClass=com.mgmtp.jira.app.jiracompatibility.api.JiraCompatibility)(objectClass=com.mgmtp.jira.app.jiracompatibility.api.JiraCompatibility))
at org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.timeout(DependencyWaiterApplicationContextExecutor.java:489)
at org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.access$000(DependencyWaiterApplicationContextExecutor.java:54)
at org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$WatchDogTask.run(DependencyWaiterApplicationContextExecutor.java:109)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
2020-05-20 11:20:26,883+0700 Spring DM Context Creation Timer ERROR [o.e.g.b.e.internal.support.ExtenderConfiguration] Application context refresh failed (NonValidatingOsgiBundleXmlApplicationContext(bundle=com.mgmtp.jira.app.smart-panels-app, config=osgibundle:/META-INF/spring/
.xml))
org.springframework.context.ApplicationContextException: Application context initialization for ‘com.mgmtp.jira.app.smart-panels-app’ has timed out waiting for (&(objectClass=com.mgmtp.jira.app.jiracompatibility.api.JiraCompatibility)(objectClass=com.mgmtp.jira.app.jiracompatibility.api.JiraCompatibility))
at org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.timeout(DependencyWaiterApplicationContextExecutor.java:489)
at org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.access$000(DependencyWaiterApplicationContextExecutor.java:54)
at org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$WatchDogTask.run(DependencyWaiterApplicationContextExecutor.java:109)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
2020-05-20 11:20:26,883+0700 Spring DM Context Creation Timer ERROR [o.e.g.b.e.i.dependencies.startup.DependencyWaiterApplicationContextExecutor] Unable to create application context for [com.mgmtp.jira.app.smart-panels-app], unsatisfied dependencies: Dependency on [(&(objectClass=com.mgmtp.jira.app.jiracompatibility.api.JiraCompatibility)(objectClass=com.mgmtp.jira.app.jiracompatibility.api.JiraCompatibility))] (from bean [&jiraCompatibility])
org.springframework.context.ApplicationContextException: Application context initialization for ‘com.mgmtp.jira.app.smart-panels-app’ has timed out waiting for (&(objectClass=com.mgmtp.jira.app.jiracompatibility.api.JiraCompatibility)(objectClass=com.mgmtp.jira.app.jiracompatibility.api.JiraCompatibility))
at org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.timeout(DependencyWaiterApplicationContextExecutor.java:489)
at org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.access$000(DependencyWaiterApplicationContextExecutor.java:54)
at org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$WatchDogTask.run(DependencyWaiterApplicationContextExecutor.java:109)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)

I open osgi browser and I saw, in bundle-classPath, the jar file was added.

  1. Try to click enable plugin I got this log

2020-05-20 11:25:51,644+0700 http-nio-2990-exec-9 INFO admin 685x2439x1 1dlbvhx 0:0:0:0:0:0:0:1 /rest/plugins/1.0/com.mgmtp.jira.app.smart-panels-app-key [c.a.plugin.util.WaitUntil] Plugins that have yet to be enabled: (1): [com.mgmtp.jira.app.smart-panels-app], 282 seconds remaining
2020-05-20 11:25:52,647+0700 http-nio-2990-exec-9 INFO admin 685x2439x1 1dlbvhx 0:0:0:0:0:0:0:1 /rest/plugins/1.0/com.mgmtp.jira.app.smart-panels-app-key [c.a.plugin.util.WaitUntil] Plugins that have yet to be enabled: (1): [com.mgmtp.jira.app.smart-panels-app], 281 seconds remaining
2020-05-20 11:25:53,649+0700 http-nio-2990-exec-9 INFO admin 685x2439x1 1dlbvhx 0:0:0:0:0:0:0:1 /rest/plugins/1.0/com.mgmtp.jira.app.smart-panels-app-key [c.a.plugin.util.WaitUntil] Plugins that have yet to be enabled: (1): [com.mgmtp.jira.app.smart-panels-app], 280 seconds remaining
2020-05-20 11:25:54,649+0700 http-nio-2990-exec-9 INFO admin 685x2439x1 1dlbvhx 0:0:0:0:0:0:0:1 /rest/plugins/1.0/com.mgmtp.jira.app.smart-panels-app-key [c.a.plugin.util.WaitUntil] Plugins that have yet to be enabled: (1): [com.mgmtp.jira.app.smart-panels-app], 279 seconds remaining
2020-05-20 11:25:55,653+0700 http-nio-2990-exec-9 INFO admin 685x2439x1 1dlbvhx 0:0:0:0:0:0:0:1 /rest/plugins/1.0/com.mgmtp.jira.app.smart-panels-app-key [c.a.plugin.util.WaitUntil] Plugins that have yet to be enabled: (1): [com.mgmtp.jira.app.smart-panels-app], 278 seconds remaining
2020-05-20 11:25:56,654+0700 http-nio-2990-exec-9 INFO admin 685x2439x1 1dlbvhx 0:0:0:0:0:0:0:1 /rest/plugins/1.0/com.mgmtp.jira.app.smart-panels-app-key [c.a.plugin.util.WaitUntil] Plugins that have yet to be enabled: (1): [com.mgmtp.jira.app.smart-panels-app], 277 seconds remaining
2020-05-20 11:25:57,657+0700 http-nio-2990-exec-9 INFO admin 685x2439x1 1dlbvhx 0:0:0:0:0:0:0:1 /rest/plugins/1.0/com.mgmtp.jira.app.smart-panels-app-key [c.a.plugin.util.WaitUntil] Plugins that have yet to be enabled: (1): [com.mgmtp.jira.app.smart-panels-app], 276 seconds remaining
2020-05-20 11:25:58,661+0700 http-nio-2990-exec-9 INFO admin 685x2439x1 1dlbvhx 0:0:0:0:0:0:0:1 /rest/plugins/1.0/com.mgmtp.jira.app.smart-panels-app-key [c.a.plugin.util.WaitUntil] Plugins that have yet to be enabled: (1): [com.mgmtp.jira.app.smart-panels-app], 275 seconds remaining
2020-05-20 11:25:59,664+0700 http-nio-2990-exec-9 INFO admin 685x2439x1 1dlbvhx 0:0:0:0:0:0:0:1 /rest/plugins/1.0/com.mgmtp.jira.app.smart-panels-app-key [c.a.plugin.util.WaitUntil] Plugins that have yet to be enabled: (1): [com.mgmtp.jira.app.smart-panels-app], 274 seconds remaining
2020-05-20 11:26:00,665+0700 http-nio-2990-exec-9 INFO admin 685x2439x1 1dlbvhx 0:0:0:0:0:0:0:1 /rest/plugins/1.0/com.mgmtp.jira.app.smart-panels-app-key [c.a.plugin.util.WaitUntil] Plugins that have yet to be enabled: (1): [com.mgmtp.jira.app.smart-panels-app], 273 seconds remaining
2020-05-20 11:26:01,669+0700 http-nio-2990-exec-9 INFO admin 685x2439x1 1dlbvhx 0:0:0:0:0:0:0:1 /rest/plugins/1.0/com.mgmtp.jira.app.smart-panels-app-key [c.a.plugin.util.WaitUntil] Plugins that have yet to be enabled: (1): [com.mgmtp.jira.app.smart-panels-app], 272 seconds remaining
2020-05-20 11:26:02,670+0700 http-nio-2990-exec-9 INFO admin 685x2439x1 1dlbvhx 0:0:0:0:0:0:0:1 /rest/plugins/1.0/com.mgmtp.jira.app.smart-panels-app-key [c.a.plugin.util.WaitUntil] Plugins that have yet to be enabled: (1): [com.mgmtp.jira.app.smart-panels-app], 271 seconds remaining
2020-05-20 11:26:03,670+0700 http-nio-2990-exec-9 INFO admin 685x2439x1 1dlbvhx 0:0:0:0:0:0:0:1 /rest/plugins/1.0/com.mgmtp.jira.app.smart-panels-app-key [c.a.plugin.util.WaitUntil] Plugins that have yet to be enabled: (1): [com.mgmtp.jira.app.smart-panels-app], 270 seconds remaining
2020-05-20 11:26:04,695+0700 http-nio-2990-exec-9 ERROR admin 685x2439x1 1dlbvhx 0:0:0:0:0:0:0:1 /rest/plugins/1.0/com.mgmtp.jira.app.smart-panels-app-key [c.a.plugin.manager.PluginEnabler] Unable to start the following plugins due to timeout while waiting for plugin to enable: com.mgmtp.jira.app.smart-panels-app

Did I do something wrong here?
Looking for your help.

Cheers,

Sounds like you’re writing a library which would also be useful over here: Looking for bridge API lib for compatibility jira-api version 7.x and 8.x, similar to jira-cross-compatibility-lib-bridge-api

How do you inject the JiraCompatibility into your app. It’s likely that you’re doing something wrong with the dependency injection. The OSGi exeception indicates, that the dependency injection is looking for an exported instance of JiraCompatibility. But you’re using scope compile for the dependency, so a simple instantiation of the required class should be sufficient.

Hi, @dennis.fischer
Yes, I try to create a bridge like that topic.
Inside the project JiraCompatibility, it just have one interface and one impl for demo
The interface:

public interface JiraCompatibility {

 List<Issue> demo(String a);
}

The Impl:

@ExportAsService({JiraCompatibility.class})
@Named("jiraCompatibility")
public class JiraCompatibilityImpl implements JiraCompatibility {
  public List<Issue> demo(String a) {
    return null;
  }
}

In the pom.xml has < packaging> jar and < Export-Package> like this

<packaging>jar</packaging>
....
<instructions>
            <Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>

            <!-- Add package to export here -->
            <Export-Package>
              com.mgmtp.jira.app.jiracompatibility.api,
            </Export-Package>

            <!-- Add package import here -->
            <Import-Package>org.springframework.osgi.*;resolution:="optional",
              org.eclipse.gemini.blueprint.*;resolution:="optional", *;resolution:="optional"
            </Import-Package>

            <!-- Ensure plugin is spring powered -->
            <Spring-Context>*</Spring-Context>
          </instructions>