Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Multiple Classes ... Should I inject, or make Global?


I am starting to create "packages" so that my scripting is more stable and more scalable. I am using Jira Server / Scriptrunner as my means of executing said scripts.

For instance, I created a "logger" package to control default behavior on what gets logged and what does not.  "debug" and "info" are normally toggled off, but "error" is normally toggled on


import utils.LogThis

log = new LogThis()
log.debug("This will log because I just turned debug on")"This will NOT log because info is toggled off by default")

Backstory: I have a "controller" script that imports two other classes.  Logger and Assignee.  Logger is what I just explained, and the Assignee Class handles logic to "re-assign" an issue to another person.  Simple enough.

Issue: I want to set the "log level" for my class in the initial script and have both Logger and Assignee instruction to respect that state.  This is not going to happen if I am "newing" up LogThis in each of the two classes.

Normally, to solve this, I would "inject" the Logger into each class when I "new it up". 

assignee = new Assignee(log, $issue, $assignee)

Is that best way to handle this in Groovy?  I like injection and would normally make a "system" object where I store any / all frameworky objects and just inject that as SOP.

system = new System()

system.log = new LogThis()


assignee = newAssignee(system, $issue, $assignee)

As each "script" is compiled to an object, I am thinking I can not really "global" the LogThis as it is probably not available to another "imported" script just by not typecasting / def'ing the variable.

Just looking for "Best Practices" on something like this.   

Thanks in advance

0 answers

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events