You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
I know that it gets used when accessing other plugins in scriptrunner code but
Should I be able to use @WithPlugin with @Field? Is there anything I need to do differently?
Hello,
There's a description of what @WithPlugin does available in the ScriptRunner documentation, here. It should appear before you use the classes from another plugin, at the top of the file. What is does in short is that it grabs the classloader from the plugin you specify and adds it to the list of classloaders that get loaded when your script compiles. Thus, classes loaded by that plugin should be made available on the script you're writing. There are a few examples of it being used in the docs as well, such as with Tempo here. As far as using it with @Field, I believe you should be able to but I haven't tested this at all, so no guarantees.
Hopefully this helps you out. :)
Jenna
Thank you for your answer. This helps make sense of some of the results I've been getting from my tests
BTW the reason for all these tests is I've been getting a lot of random java.lang.NoClassDefFoundError for scripts with the @WithPlugin statements and random changes seemed to temporarily fix the issue but I had no idea why. Still don't. Maybe it has something to do with the class loader cache.
code for each test
Test 1
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.tempoplugin.team.api.TeamManager
//@WithPlugin("com.tempoplugin.tempo-teams")
TeamManager teamManagerTemp = ScriptRunnerImpl.getPluginComponent(TeamManager)
Test 2
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.tempoplugin.team.api.TeamManager
@WithPlugin("com.tempoplugin.tempo-teams")
@WithPlugin("com.tempoplugin.tempo-platform-api")
TeamManager teamManagerTemp = ScriptRunnerImpl.getPluginComponent(TeamManager)
Test 3
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.tempoplugin.platform.api.user.TempoUser
@WithPlugin("com.tempoplugin.tempo-platform-api")
Test 4
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.tempoplugin.platform.api.user.TempoUser
@WithPlugin("com.tempoplugin.tempo-platform-api")
def x = null
Test 5
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.tempoplugin.platform.api.user.TempoUser
//Either of these 2 lines will work
//@WithPlugin("com.tempoplugin.tempo-platform-api")
@WithPlugin("com.tempoplugin.tempo-teams")
def x = null
Test 6
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import groovy.transform.Field
import com.tempoplugin.team.api.TeamManager
@WithPlugin("com.tempoplugin.tempo-teams")
@Field TeamManager teamManagerTemp = ScriptRunnerImpl.getPluginComponent(TeamManager)
Test 7
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import groovy.transform.Field
import com.tempoplugin.team.api.TeamManager
@WithPlugin("com.tempoplugin.tempo-teams")
@Field TeamManager teamManager
teamManager = ScriptRunnerImpl.getPluginComponent(TeamManager)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That sounds like you might be running into this bug, SRPLAT-77, depending on what version on SR you're using. If you keep having trouble with this or if you're on a version of SR where that bug is fixed I recommend that you submit a support inquiry over on the Adaptavist support site. We'd be able to get some more information from you over there that might help to get this working or identify the issue.
Jenna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.