Is there an a way to initialise some data in a Plugin. I am modulizing my code and it would be nice to have something like the bootstrap in the Plugin but I cannot find it. Nor can I find references using the Google.
Asked
Active
Viewed 2,890 times
12
-
1Man, thanks for asking that, appreciate it – chill appreciator Mar 12 '21 at 22:32
1 Answers
24
BootStrap.groovy is excluded by default from a plugin zip, but you can create a MyPluginBootStrap.groovy (name doesn't matter, just can't be BootStrap) and that'll be packaged and run along with the application's BootStrap.

Burt Beckwith
- 75,342
- 5
- 143
- 156
-
1plugin init stuff in doWithApplicationContext() . more details from http://grails.1312388.n4.nabble.com/Plugin-Bootstrap-question-td2529935.html – Ford Guo Nov 29 '11 at 04:04
-
Name does matter in that it needs to be different from any other XXXBootStrap.groovy that you want to be run on application startup. If two plugins have a BootStrap with the same name only one will be executed, therefor MyPluginNameBootStrap.groovy seems a save choice. – Ruben Feb 07 '12 at 12:39
-
1I tried this, created MyPluginBootStrap in my project (in the same place that boostrap would live), but it never gets called, only the applications bootstrap. Any ideas? This is in intellij (not war) – John Little Feb 04 '15 at 10:40
-
The structure of the file is important. Example filename: `MyPlugBootStrap.groovy`. Content: ` class MyPlugBootStrap { def init = { println('something') } } ` I've tried to use this file as script without class and application silently died. In general structure should be the same as in `BootStrap.groovy` in main application. – chill appreciator Mar 12 '21 at 22:29