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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With