1

I'm creating a Grails plugin which will modify the value of the following config property:

grails.gorm.default.constraints

The problem is that by the time my plugin descriptor starts running (doWithSpring) if the Grails application that uses the plugin had an existing value for the default constraints property, it would have been already executed.

I'd like my plugin to modify the value of the default constraints before Grails begins executing it so that the constraints I'm adding will also be included. The default constraints closure seems to get executed multiple times during Grails app startup.

I've tried a few approaches:

  • Use the platform-core plugin which this post talks about: How to configure a grails plugin from another grails plugin.
    • Problem there is similar: the Grails app's default constraints block is executed at least once before the plugin's doWithConfig begins to run.
  • (Hackish) Modify Grails app to include a FooConfig.groovy in its "locations", a file which exists in the plugin's grails-app/conf/ dir and thus accessible on the classpath (see below).
    • Problem: Hackish, still working through it but might be my only option.

grails.config.locations = ["classpath:FooConfig.class"] // Yes, *.class

Community
  • 1
  • 1
Vahid Pazirandeh
  • 1,552
  • 3
  • 13
  • 29
  • 1
    Somewhat similar question was recently answered [here](http://stackoverflow.com/a/23024131/2051952). Thumb rule is app config is applied in the end after all plugin configs are loaded. So anything provided by plugin can be overridden in app config. Only place I fell this can be achieved is at BootStrap which is done at the end of the application run process. I hope that answer helps. – dmahapatro May 02 '14 at 01:40
  • @dmahapatro interesting, thanks. I guess my situation is special: I want to change "bindable". What do you think about this: http://grails.1312388.n4.nabble.com/Can-the-bindable-constraint-be-changed-at-runtime-td4656566.html – Vahid Pazirandeh May 02 '14 at 19:12
  • `bindable` constraint is added by `grails-web-databinding` plugin found in `gails-core` through an AST transformation. I don't think my previous comment will be applicable for `bindable` constraint. It is not a `ConstrainedProperty` like max, maxSize, inList, etc. I fear it has to be applied in the class directly as mentioned in docs. – dmahapatro May 02 '14 at 20:46

0 Answers0