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

1 answer

0 vote

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

172 views 0 4
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