How do you access a Component from another Plugin in ScriptRunner?

I am trying to access a Component from another plugin.

The plugin's atlassian-plugin.xml contains the following definition:

<component key="xxx-dao-service" name="DAO Service" class="com.xxx.jira.plugins.xxx.service.xxxDAOServiceImpl" public="true">
<interface>com.xxx.jira.plugins.xxx.service.xxxDAOService</interface>
</component>

It is a third-party, published plugin that was bought from the Atlassian Marketplace.

ComponentManager componentManager = ComponentManager.getInstance();
PluginAccessor pluginAccessor = componentManager.getPluginAccessor();
Class daoSvcClass = pluginAccessor.getClassLoader().findClass("com.xxx.jira.plugins.xxx.service.xxxDAOService");
def serviceDao = componentManager.getOSGiComponentInstanceOfType(daoSvcClass);
log.debug(serviceDao.method(xxx,xxx,xxx))

So how do you access another plugins' components and use the methods therein?

3 answers

1 accepted

0 vote

You don't have to include it in your plugin - in fact doing so is not going to work if there are components etc. As Ash said, you should be able to use @WithPlugin and @PluginModule to get access to the services.

If you need to use third-party component you shoul include it into your plugin jar. To do this you should to spesify this into dependences section with scope <compile>. It means that this jar will be included into your jar. And then you can get any class with componentManager.getOSGiComponentInstanceOfType(daoSvcClass.class)

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

77 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you