ScriptRunner - can't find plugin module

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!

6 answers

1 vote

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}")
}
0 vote

Can you paste a bit of your source?

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
    }
	
}

I would try without the @Grab, and the @WithPlugin should annotate the class.

It has the same error without the @Grab.

and the other thing I said to try?

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

That worked!  Any idea why this is different?

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.

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...

74 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