3.3 Environments - Reference Documentation
Authors: Andres Almiray
Version: 1.2.0
3.3 Environments
Per Environment Configuration
Griffon supports the concept of per environment configuration. TheBuildConfig.groovy
file within the griffon-app/conf
directory can take advantage of per environment configuration using the syntax provided by ConfigSlurper . As an example consider the following default packaging definitions provided by Griffon:environments { development { signingkey { params { sigfile = 'GRIFFON' keystore = "${basedir}/griffon-app/conf/keys/devKeystore" alias = 'development' storepass = 'BadStorePassword' keypass = 'BadKeyPassword' lazy = true // only sign when unsigned } } } test { griffon { jars { sign = false pack = false } } } production { signingkey { params { sigfile = 'GRIFFON' keystore = 'CHANGE ME' alias = 'CHANGE ME' lazy = false // sign, regardless of existing signatures } } griffon { jars { sign = true pack = true destDir = "${basedir}/staging" } webstart { codebase = 'CHANGE ME' } } } }griffon { jars { sign = false pack = false destDir = "${basedir}/staging" jarName = "${appName}.jar" } }
environments
block too), the environments
block specifies per environment settings for the jars
property.Packaging and Running for Different Environments
Griffon's command line has built in capabilities to execute any command within the context of a specific environment. The format is:griffon [environment] [command name]
dev
, prod
, and test
for development
, production
and test
. For example to package an application for the development
(avoiding jar signing by default) environment you could do:griffon dev package
griffon.env
variable to any command:griffon -Dgriffon.env=UAT run-app
Programmatic Environment Detection
Within your code, such as in a Gant script or a bootstrap class you can detect the environment using the Environment class:import griffon.util.Environment...switch(Environment.current) { case Environment.DEVELOPMENT: configureForDevelopment() break case Environment.PRODUCTION: configureForProduction() break }
Generic Per Environment Execution
You can use thegriffon.util.Environment
class to execute your own environment specific logic:Environment.executeForCurrentEnvironment { production { // do something in production } development { // do something only in development } }