Grails将config.properties值用于BuildConfig.groovy [英] Grails use config.properties value into BuildConfig.groovy
本文介绍了Grails将config.properties值用于BuildConfig.groovy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 conf
目录下有一个 config.properties
文件。
并在上面的文件中有一个条目,如下所示: grails.tomcat.version = 2.2.4
。
and have a entry in the above file like this: grails.tomcat.version = 2.2.4
.
如何在 BuildConfig.groovy
文件中使用此值?
How can I use this value in BuildConfig.groovy
file?
假设:
plugins = {
build ":tomcat:{here i want to use the config value}"
}
推荐答案
您可以阅读 / code>文件如下:
You can do read the properties
file as below:
plugins {
def props = new Properties()
new File("grails-app/conf/config.properties").withReader{
props.load(it)
}
def slurp = new ConfigSlurper().parse(props)
build ":tomcat:$slurp.grails.tomcat.version"
}
如果您只从属性文件中使用该单个条目,则看不到其中的值。我宁愿在 Config.groovy
中定义该配置。
I do not see a value out of it if you only have that single entry to use from the properties file. I would rather have that config defined in Config.groovy
.
这篇关于Grails将config.properties值用于BuildConfig.groovy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文