Scriptrunner - "Unable to resolve class" despite autocomplete? Edited

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

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

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

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

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,242 views 14 20
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot