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

This widget could not be displayed.

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}")
}
This widget could not be displayed.

Can you paste a bit of your source?

This widget could not be displayed.

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.

This widget could not be displayed.

It has the same error without the @Grab.

and the other thing I said to try?

This widget could not be displayed.

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

This widget could not be displayed.

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 Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Jul 25, 2018 in Marketplace Apps

Jira Cloud and Bitbucket Cloud Integration with Microsoft Teams

One of the newest products in the Microsoft family - Microsoft Teams,  is a chat-based hub for teamwork that integrates all the people, content, and tools your team needs to be more engaged and ...

718 views 0 3
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