Scripting Other Plugins not working in script under script root

Paul Wolf March 27, 2018

I'm writing a Groovy script that uses the @WithPlugin and @PluginModule annotations to access classes provided by another plugin.  I'm using ScriptRunner for JIRA version 5.3.9.  The documentation at https://scriptrunner.adaptavist.com/latest/jira/scripting-other-plugins.html states "These annotations only work when running a script that is under a script root…​ not a script outside a script root, nor code pasted into the console."

However, I'm finding the opposite -- the annotations seem to work when using a script pasted into the console, but I see the following exception when I run the same script from a file that is under a script root,  Can you tell me if the documentation is out of date, or is the code not working as expected?  Thanks.

2018-03-27 15:36:12,094 WARN [common.UserScriptEndpoint]: Script console script failed: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: General error during semantic analysis: Cannot set plugin module when field already initialised java.lang.Exception: Cannot set plugin module when field already initialised at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83) at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247) at com.onresolve.scriptrunner.runner.customisers.PluginModuleCompilationCustomiser.transformDeclaration(PluginModuleCompilationCustomiser.groovy:89) at com.onresolve.scriptrunner.runner.customisers.PluginModuleCompilationCustomiser$transformDeclaration.callCurrent(Unknown Source) at com.onresolve.scriptrunner.runner.customisers.PluginModuleCompilationCustomiser.transform(PluginModuleCompilationCustomiser.groovy:47) at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitExpressionStatement(ClassCodeExpressionTransformer.java:142)

 

4 answers

0 votes
Nicolas Esteves November 16, 2018

Hello Paul,

Can you please try that instead of the ScriptRunner annotations?

import com.atlassian.jira.component.ComponentAccessor

def pluginAccessor = ComponentAccessor.getPluginAccessor();
def plugin = pluginAccessor.getPlugin("com.valiantys.jira.plugins.SQLFeed");
def serviceClass = plugin.getClassLoader().loadClass("com.valiantys.nfeed.api.IFieldValueService");

def fieldValueService = ComponentAccessor.getOSGiComponentInstanceOfType(serviceClass);

Source: https://valiantys.atlassian.net/wiki/spaces/NFEED512X/pages/101154882/Use+case+Access+nFeed+API+in+a+Groovy+script

Regards,

Nicolas 

0 votes
Marcin Pelzner October 17, 2018

Hi,

switching to the following helped in my case:

static final private Class serviceDeskManagerClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.atlassian.servicedesk.api.ServiceDeskManager")
static final private ServiceDeskManager serviceDeskManager = ComponentAccessor.getOSGiComponentInstanceOfType(serviceDeskManagerClass) as ServiceDeskManager

static final private Class organizationServiceClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.atlassian.servicedesk.api.organization.OrganizationService")
static final private OrganizationService organizationService = ComponentAccessor.getOSGiComponentInstanceOfType(organizationServiceClass) as OrganizationService

don't forget to import the classes, though.

0 votes
Vendor Support May 21, 2018

I'm having the same issue.. 

0 votes
Dennis Markwart May 2, 2018

I have the same problem. Annotations @WithPlugin and @PluginModule are working in the script console, but unfortunately not in a script file under scripts root.

Script Runner Version is 5.2.1 and i am trying to work with the nFeed plugin api (IFieldValueService). 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events