Details
-
Bug
-
Status: Done
-
Major
-
Resolution: Done
-
3.0.6, 4.3.19, 5.5.7
-
None
-
JIRA 6.2.7 Server
-
5.7
Description
I'm testing the switch from 2.x to Script Runner 3.0.6. I have a helper class
JiraTools within the package eventim. For 2.x of Script Runner this class was saved under atlassian-jira/WEB-INF/classes/eventim/JiraTools.groovy and all other scripts could use this class via import eventim.JiraTools.
For SR 3.0.6 this doesn't work anymore. Within the console for example I get the error
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script9.groovy: 1: unable to resolve class eventim.JiraTools @ line 1, column 1. import eventim.JiraTools as ejt ^ 1 error
I copied the file to jirahome/scripts/eventim/JiraTools.groovy but that doesn't help.
This problem doesn't affect every ScriptRunner extension point. Specifically, you can import classes from your Script Root in a Behaviour, but not in a workflow Post Function.
Known Workarounds
Eval the shared script file
Inelegant, but effective, you can call Groovy's evaluate method on the script file that contains code you want to reuse, rather than using an import statement. e.g.
evaluate(new File("/path/to/your/script/root/HelloWorld.groovy")) // open and evaluate file (change the file path to your helper class)
Put shared class in a Script Plugin
Another more involved workaround would be to put your utility class inside a Script Plugin. You could then import it into your post function using the @WithPlugin annotation as described in the documentation on scripting other plugins. Creating a script plugin is a more intense workaround, requiring a bit of developer expertise.
Attachments
Issue Links
- is duplicated by
-
SRJIRA-1384 import of helper class not possible - File based scripts used GroovyScriptEngine and in-line scripts use GroovyShell
-
- Done
-
- is related to
-
SRJIRA-2402 As a JIRA Administrator, I need to be able to load Conditions and Validators from source files so my whole ScritpRunner customization can be code reviewed and deployed to a file system
-
- Done
-
- relates to
-
SRJIRA-2228 Web item condition cached when in a script file
-
- Done
-
-
SRJIRA-2855 Pull inline scripts into a specified IDEA project, rather than autogenerated
-
- Done
-
- mentioned in
-
Page Loading...