Uploaded image for project: 'SR for Jira - Development'
  1. SR for Jira - Development
  2. SRJIRA-458

import of helper class not possible

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Done
    • Major
    • Resolution: Done
    • 3.0.6, 4.3.19, 5.5.7
    • 5.6.1
    • 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

          Activity

            People

              merdmann Marcin Erdmann [X] (Inactive)
              htietgens Henning Tietgens (Inactive)
              Votes:
              30 Vote for this issue
              Watchers:
              44 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: