Grails 3 Plugin Config Files

334 views
Skip to first unread message

Aaron

unread,
Oct 29, 2015, 6:24:14 PM10/29/15
to Grails Dev Discuss
We have a couple of projects that shared an inline plugin in Grails 2. I've switched to using the Gradle sub-project (which is nice) but I'm a little unsure of how the configuration is supposed to work.

For example, we had a plugin called "common" (original, I know) that had some common configuration in CommonConfig.groovy. Now it seems like application.groovy is where the config should go, but I think that will be overridden by the application.groovy in my application (or it seems to be).

If I want to have some base configuration in a plugin that can be used by the application, what's the best way to do that in Grails 3?

Also, it's not clear what are the rules if you have both an application.yml and an application.groovy, which one takes precendence? I assume they are sort of merged together (hopefully the groovy one would override the YML file). The docs don't really seem to discuss it.

Thanks,
-Aaron

Sergio Michels

unread,
Oct 29, 2015, 8:11:36 PM10/29/15
to grails-de...@googlegroups.com
I was just watching Grails 3.x update and Graeme said that if you have both groovy and yml application files they get merged.

Not sure yet the order of the files in the merge.  

--
Sérgio Michels

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-disc...@googlegroups.com.
To post to this group, send email to grails-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/849b05a0-064c-4da0-a45a-932e8bd8b7d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sergio Michels

unread,
Oct 29, 2015, 8:18:51 PM10/29/15
to grails-de...@googlegroups.com
And I'm interesting in this topic too, currently working on the Melody plugin migration and just left the original code

static ConfigObject getGrailsMelodyConfig(GrailsApplication application) {
  def config = application.config
  GroovyClassLoader classLoader = new GroovyClassLoader(application.getClassLoader())
  try {
  config.merge(new ConfigSlurper(Environment.current.name().toLowerCase()).parse(classLoader.loadClass('GrailsMelodyConfig')))
  } catch (Exception e) {
  // ignored, use defaults
  }
  return config
}

--
Sérgio Michels

Graeme Rocher

unread,
Oct 31, 2015, 8:17:41 AM10/31/15
to grails-de...@googlegroups.com

In 3.x if you define a plugin.yml file the configure in this file becomes the defaults and is available to the application.

The application can also override the config but still access the default values using the "grails.plugin.foo" prefix where "foo" is the plugin name 

Aaron

unread,
Nov 5, 2015, 11:00:30 AM11/5/15
to Grails Dev Discuss
Cool, that works for plugin.yml but does not seem to care or know about a plugin.groovy. Would be nice if it was consistent with the way application.groovy and application.yml work.

I assume the response to that statement might be "contributions are always welcome" ;)

Thanks,
Aaron

--
Sérgio Michels


--
Sérgio Michels

To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-discuss+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-discuss+unsub...@googlegroups.com.

Christian Oestreich

unread,
Dec 8, 2015, 4:02:25 PM12/8/15
to Grails Dev Discuss
@Graeme Does the environment setting get interrogated in this scheme and also work for plugin-development.yml (i.e. plugin-[environment].yml?

Christian Oestreich

unread,
Dec 8, 2015, 4:35:21 PM12/8/15
to Grails Dev Discuss
I was hoping that the enviroments property would work in the plugin.yml but I have confirmed that it is not and will either show the base property 'plugin.yml' or the spring value ${plugin.name} when using the following plugin.yml file in a plugin.

plugin:
name: plugin.yml

environments:
dev:
plugin:
name: env-dev-plugin.yml
prod:
plugin:
name: env-prod-plugin.yml
development:
plugin:
name: env-development-plugin.yml
production:
plugin:
name: prod-development-plugin.yml
Reply all
Reply to author
Forward
0 new messages