Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

define custom grails environment

Tags:

grails

groovy

Based on this question, I thought I could define something like this in (for example) resources.groovy

def currentEnv = Environment.current
if (currentEnv == Environment.CUSTOM && currentEnv.name == 'mock') {
    println 'Do some stuff for the mock env'
}

The code in the if-statement should be executed when I run (for example) grails run-app -Denv=mock but it isn't, what am I doing wrong?

like image 206
Dónal Avatar asked Jun 27 '26 17:06

Dónal


1 Answers

You must use the method Environment.executeForCurrentEnvironment(), like this:

import grails.util.Environment

     grails.util.Environment.executeForCurrentEnvironment {
         development {
             println 'Running in DEV mode.'
         }
         production {
             println 'Running in production mode.'
         }
         mock {
             println 'Running in custom "mock" mode.'
         }
     }

and call grails this way: grails -Dgrails.env=mock run-app

Take a look at this blogpost, from mrhaki.

like image 182
deluan Avatar answered Jun 29 '26 08:06

deluan