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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

358 views 0 6
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