I have a scripted listener that works when a JIRA event occurs. I am trying to include the Structure plugin within this scripted listener. Using your wiki on Scripting Other Plugins, I tried incorporating your minimal example for listing structures from the Structure plugin into my script. However, it is giving me this error when I try to add/preview the script in JIRA: Problem loading class: java.lang.Exception: Can't find plugin module for class: com.almworks.jira.structure.api.StructureServices, check the plugin is installed / enabled / licensed.
I am using JIRA 6.2.1, Structure 2.10.1, and ScriptRunner 3.0.12. I have set a script root on JAVA_OPTS where my script is located. Is there something else I need to do to get the plugin module into my script so I can access Structure? Thanks!
I just tried it with the latest version of structure and it worked fine.
Can you put the following in a file, and go to Admin -> Script Console, point to the file and run.
package examples.docs import com.almworks.jira.structure.api.PermissionLevel import com.atlassian.jira.component.ComponentAccessor import com.onresolve.scriptrunner.runner.customisers.PluginModule import com.onresolve.scriptrunner.runner.customisers.WithPlugin import com.almworks.jira.structure.api.StructureServices // Specify that classes from this plugin should be available to this script @WithPlugin("com.almworks.jira.structure") // Inject plugin module @PluginModule StructureServices structureServices def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() //noinspection GroovyVariableNotAssigned def structureManager = structureServices.getStructureManager() def structures = structureManager.getAllStructures(user, PermissionLevel.VIEW, false) structures.each {structure -> log.debug("Structure: ID: ${structure.id}, name: ${structure.name}") }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Looking again at your code it's wrong... the @PluginModule stuff should be outside of the constructor. But it doesn't really explain the error you got.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As you suggested, I tried annoting the class with @WithPlugin. To be clear and check that I am doing the right thing, I moved the @WithPlugin to be right before the line declaring class StructureTest. This gave me the same error.
I also tried putting your AddIssueToStructure example in a post-function script without a class (changing only the structure api version and structure name) and got the same error.
Capture.PNG
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
and the other thing I said to try?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is a stripped down version of the source code that still has the same error:
package com.torc.listener import com.atlassian.jira.event.issue.AbstractIssueEventListener import com.atlassian.jira.component.ComponentAccessor import com.almworks.jira.structure.api.PermissionLevel import com.onresolve.scriptrunner.runner.customisers.PluginModule import com.onresolve.scriptrunner.runner.customisers.WithPlugin import com.almworks.jira.structure.api.StructureManager import com.almworks.jira.structure.api.StructureServices import com.onresolve.scriptrunner.runner.util.UserMessageUtil import org.apache.log4j.Category class StructureTest extends AbstractIssueEventListener { StructureTest() { // Grab only useful for IDE help, not for runtime. Alternatively you can just add this jar to the // "provided" scope for the module @Grab(group = 'com.almworks.jira.structure', module = 'structure-api', version = '8.7.0') // Specify that classes from this plugin should be available to this script @WithPlugin("com.almworks.jira.structure") // Inject plugin module @PluginModule StructureServices structureServices def structureManager = structureServices.getStructureManager() getStructureNames(structureManager) } void getStructureNames(structureManager) { def user = ComponentAccessor.getUserManager().getUserByName("scriptrunner") def structures = structureManager.getAllStructures(user, PermissionLevel.VIEW, false) List<String> structureNames structures.each {structure -> structureNames.add(structure.name)} structureNames //set breakpoint to view names in IDEA } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I would try without the @Grab, and the @WithPlugin should annotate the class.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you paste a bit of your source?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.