Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 21:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Hi,
I try to use the ConfigSlurper but got a ton of exceptions, can I use it with Script Runner?
def config = new ConfigSlurper()
config.parse('''
app.age = 42
app {
name = "343"
}
''')
2016-02-29 11:22:11,860 http-nio-8080-exec-22 ERROR 682x15586x1 14b7680 127.0.0.1 /rest/api/2/issue/10103/comment [c.o.scriptrunner.runner.AbstractScriptListener] *************************************************************************************
2016-02-29 11:22:11,860 http-nio-8080-exec-22 ERROR 682x15586x1 14b7680 127.0.0.1 /rest/api/2/issue/10103/comment [c.o.scriptrunner.runner.AbstractScriptListener] Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: JSDIssueCommented
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during class generation: java.lang.NoClassDefFoundError: groovy/lang/Script
The problem seems to be the parse(), log.debug shows me "groovy.util.ConfigSlurper@278dab4c" on config var
ConfigSlurper is a bit mad, I try to avoid it. The following seems to work but there are better ways:
str = ... def script = new GroovyShell().parse(str) log.debug config.parse(script)
Ah, great, works! Thank you!
I´m eager to learn, so what are the better ways?
What I want to do:
Have 2 config scripts, one for development and one for production. Our build server decides which gets delivered based on the environment. Maybe some file exist voodoo to have some sane production defaults and if development file exists then it´s overriding the production values.
This works so far:
ConfigSlurper configSlurper = new ConfigSlurper()
ConfigObject config = configSlurper.parse(new GroovyShell().parse(this.class.getResource("config/production.groovy").text))
URL developmentUrl = this.class.getResource("config/development.groovy")
if (developmentUrl) {
config.merge(configSlurper.parse(new GroovyShell().parse(developmentUrl.text)))
log.debug config.teams.packers
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That seems reasonable... the problem with the method I gave you is because it creates a new shell, the compiled script is not cached. The better way would be to reuse the shell and classloader from the plugin, which would allow caching. But I couldn't do that quickly... we use a similar technique for a project here. Can't remember the details but I think a system property points to the location of the config, which differs for differing environments.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I´m not that deep into groovy, yet. But good to know, thank you.
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.