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)
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);
Regards,
Nicolas
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm having the same issue..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.