Grails BuildConfig.groovy中基于环境的WAR名称

Grails BuildConfig.groovy中基于环境的WAR名称,grails,deployment,ggts,grails-2.4,Grails,Deployment,Ggts,Grails 2.4,我想根据appName、appVersion和Environment.current的简称自动命名WAR文件。我在BuildConfig.groovy中设置了以下选项: String currentEnvShortName = Environment.envNameMappings.find{it.value == Environment.current.name}.key def f = new File("grails-app/conf/config.properties") f.text

我想根据
appName
appVersion
Environment.current的简称自动命名WAR文件。我在
BuildConfig.groovy
中设置了以下选项:

String currentEnvShortName = Environment.envNameMappings.find{it.value == Environment.current.name}.key

def f = new File("grails-app/conf/config.properties")
f.text = ""
f << "Current Env: ${currentEnvShortName}"

grails.project.war.file = "target/war/${appName}-${appVersion.toString().replaceAll(/\./,' ').split().join("-")}${currentEnvShortName}.war"
String currentEnvShortName=Environment.envNameMappings.find{it.value==Environment.current.name}.key
def=new文件(“grails-app/conf/config.properties”)
f、 text=“”

好吧,我多次尝试了你的方案,但都无法重现。但是,如果出于某种原因,它不适用于您的,您可以使用另一种方法,如下所示:

BuildConfig.groovy
中修改代码,如下所示:

// Define a custom mapping so that you can easily extend for custom environments (which will not be possible via "Environment.current.envNameMappings"
Map envNameMappings = [test: "test", development: "dev", production: "prod"]

// Read the currrent environment from System property
String currentEnv = System.getProperty("grails.env")

println currentEnv
// And this is the short name of environment you want
println envNameMappings[currentEnv]

此问题仅在Windows上的Groovy Grails工具套件的内置命令行中出现。如果从Windows CMD执行
war
命令,则正确使用环境


但是,当从Windows CMD执行时,编码会中断。我已经在中解决了这个具体问题。

我可以在新创建的项目中复制它;但是,这个问题只在GGTS(Eclipse)命令行中出现。我更新了我的答案。我想知道Eclipse的执行方式有什么不同。似乎它并不总是正确地获取当前环境。