Grails 在 BuildConfig.groovy 中使用 config.properties 值 [英] Grails use config.properties value into BuildConfig.groovy

查看:31
本文介绍了Grails 在 BuildConfig.groovy 中使用 config.properties 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 conf 目录下有一个 config.properties 文件.

I have a config.properties file under conf directory.

并在上面的文件中有一个这样的条目: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}"
}

推荐答案

您可以阅读properties文件如下:

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 在 BuildConfig.groovy 中使用 config.properties 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆