Scriptrunner - "Unable to resolve class" despite autocomplete?

Marcus Scholle June 17, 2017

Hey together,

so I'ld like to develop and automate some custom workflows and we're using Scriptrunner for this.

The configuration:

JIRA: 7.3.7
Scriptrunner: 5.0.4
Other plugins such as LabelManger
Developing and debugging over IDEA against a localhost-Installation

Now, so far it's working good but I'm having some general issues with importing other classes or plugins. Autocomplete works when the jar is referenced. However, when triggering the execution, it's always responding with "Unable to resolve class" for the external class. This is even the case for my own custom classes that're placed below the main script in the directory.

-MainScript
+HelperDirectory
+-HelperClass

Some exemplaric code I'm using:

...
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.almworks.jira.structure.AllPublicStructureComponents

// Specify that classes from this plugin should be available to this script
@WithPlugin("com.almworks.jira.structure")

// Inject plugin module
@PluginModule
AllPublicStructureComponents structureComponents

Note: I'm not sure if the documentation is outdated on that, but I can't find an actual "API" folder in the actual version of Structure.

I'm able to load at least my own classes with a construct like this but it's really uncomfortable and I'm loosing stuff like autocompletion:

    File sourceFile = new File("D:\\Programming\\Idea\\ScholledevJIRAScriptrunner\\src\\main\\scholledev\\HelperClasses\\BBCodeBlockLibrary.groovy");
    Class groovyClass = new GroovyClassLoader(getClass().getClassLoader()).parseClass(sourceFile);
    GroovyObject stringMapLibClass = (GroovyObject) groovyClass.newInstance();

Is this an actual issue with Scriptrunner or am I doing something fundamentally wrong?

Greetings Marcus

1 answer

2 votes
Daniel Yelamos [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 19, 2017

Hello Marcus.

Recently we have seen a few issues that relate to being unable to resolve a class from an outside plugin or jar. They have been solved by placing the "@WithPlugin" diretive as the latest import on your import list.

Can you try setting up your file imports like so:

...
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.almworks.jira.structure.AllPublicStructureComponents

// Inject plugin module
@PluginModule
AllPublicStructureComponents structureComponents

// Specify that classes from this plugin should be available to this script
@WithPlugin("com.almworks.jira.structure")

If this doesn't solve you issue let me know.

Cheers!

DYelamos

Marcus Scholle June 19, 2017

Thanks for your reply.

However, this does not help in my case.

Actually I don't think it's necessary an issue on Scriptrunners end.
I'm even unable to import one of my own classes that're residing in the same project.

To better visualize it, this is a screenshot of my project tree:

 SR_IDEA_ProjectTree.png

"BugTransitionMoreInfo" is my "Main class" in this context, where I would like to import "BBCodeBlockLibrary" into. 

So the start of "BBCodeBlockLibrary looks like this:

package HelperClasses

class BBCodeBlockLibrary {

 Then I'm using this code to import my class in "BugTransitionMoreInfo".

import HelperClasses.BBCodeBlockLibrary

Autocompletion works this way (so I'm seeing the corresponding methods and stuff) in my main class. However, when executing this in JIRA, all the times I'm getting "Unable to resolve class".

Daniel Yelamos [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 20, 2017

Hello Marcus, 

Did you add the directory to your script roots?

If not, you can find this community question in which Jamie Echlin explains how to set this up properly. If this does not help you, please let me know.

Cheers

Dyelamos

Akshatha July 8, 2019

Hi Daniel

I am facing the similar issue getting below error while adding new issue to the structure.

org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'com.almworks.jira.structure.AllPublicStructureComponents@16b28350' with class 'com.almworks.jira.structure.AllPublicStructureComponents' to class 'com.almworks.jira.structure.api.StructureComponents'

Above error gets resolved on using 

import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.almworks.jira.structure.AllPublicStructureComponents

// Inject plugin module
@PluginModule
AllPublicStructureComponents structureComponents

// Specify that classes from this plugin should be available to this script
@WithPlugin("com.almworks.jira.structure")

But, error occurs for RowManager.

 

Versions currently used are

Structure verison : 5.4.0

Script runner version : 5.5.7

JIRA Server version : 7.10.1

 

Any help would be appreciated.

 

Thanks

Steffen Becker March 3, 2022

Hello @Marcus Scholle 

I am facing the same issue.

Did you find a solution?

Dennis Alexander March 14, 2024

I'm facing the same issue with my own plugin module component that I'd like to use in scriptrunner scripts. I know it's something to do with ClassLoaders, yet can't understand how to overcome it.

Suggest an answer

Log in or Sign up to answer