I try to use the ConfigSlurper but got a ton of exceptions, can I use it with Script Runner?


def config = new ConfigSlurper()

app.age = 42
app {
name = "343"

2016-02-29 11:22:11,860 http-nio-8080-exec-22 ERROR 682x15586x1 14b7680 /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 /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

1 answer

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

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.

I´m not that deep into groovy, yet. But good to know, thank you.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Feb 07, 2019 in Marketplace Apps

A Timeless Love Story

It started as any story starts, on a normal, rainy day.   Admin meets App, and her name was Klok2, and like any first relationship we were both trying to make it work but neither one knew what...

469 views 8 27
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you