Create
cancel
Showing results for
Search instead for
Sign up Log in

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

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

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

Giller_ Florian

I've actually has resolved this.

The problem I had was that the interface was described as groovy interface.

So now I have interface described as java and implementation as groovy.

I was able to resolve this by:

1. Describe interface as Java Interface

2. add java folder to the source folder

<!-- We add java source files to the build -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

3. replace gmavenplus complier

<!-- And we switch off the standard gmaven compiler -->
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<executions>
<execution>
<phase>none</phase>
</execution>
</executions>
</plugin>

with
groovy-eclipse-compiler

<!-- We install and configure Groovy Eclipse Compiler -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<compilerArguments>
<indy/><!-- optional; supported by batch 2.4.12-04+ -->
<!--<configScript>config.groovy</configScript>--><!-- optional; supported by batch 2.4.13-02+ -->
</compilerArguments>
<failOnWarning>true</failOnWarning><!-- optional; supported by batch 2.5.8-02+ -->
<fork>true</fork><!-- optional; enables Parrot Parser by default for Groovy 3+ -->
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>3.9.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>3.0.8-01</version>
</dependency>
</dependencies>
</plugin>
AUG Leaders

Atlassian Community Events