如何在BuildConfig中访问grails 2.3.2

时间:2017-07-26 13:37:34

标签: grails

我正在尝试从config.grooy属性设置依赖项版本。我在这里找到了一种方法:pritomkumar.blogspot。这是建议的解决方案:

  

在' BuildConfig.groovy'中包含以下内容。文件

def directory = new File(getClass().protectionDomain.codeSource.location.path).parent;
def config = new ConfigSlurper(grailsSettings.grailsEnv).parse(new File(directory + File.separator + "Config.groovy").toURI().toURL())
println "| Tomcat Version (API): " + config.grails.tomcat.version;
....    
plugins {
    runtime ":hibernate:2.2.4"
    runtime ":jquery:1.8.3"
    runtime ":resources:1.2"

    // Uncomment these (or add new ones) to enable additional resources capabilities
    //runtime ":zipped-resources:1.0"
    //runtime ":cached-resources:1.0"
    //runtime ":yui-minify-resources:0.1.5"

    build ":tomcat:"+config.grails.tomcat.version

    runtime ":database-migration:1.3.2"

    compile ':cache:1.0.1'
}
  

在' Config.groovy'

中加入以下内容
grails.tomcat.version = "2.2.4" 

但它看起来适用于较旧的grails版本,因为当我尝试刷新依赖时,我得到了错误

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
script15010760392501179421923.groovy: 1: unable to resolve class com.whatever.configuration.ConfigurationFilesManager
 @ line 1, column 1.
   import com.whatever.configuration.ConfigurationFilesManager
   ^

1 error

    at BuildConfig.run(BuildConfig.groovy:17)
    at grails.util.BuildSettings.loadConfig(BuildSettings.groovy:1087)
    at grails.util.BuildSettings.loadConfig(BuildSettings.groovy)
    at grails.util.BuildSettings.loadConfig(BuildSettings.groovy:1073)
    at grails.util.BuildSettings.loadConfig(BuildSettings.groovy)
    at grails.util.BuildSettings$loadConfig$0.callCurrent(Unknown Source)
    at grails.util.BuildSettings.loadConfig(BuildSettings.groovy:1053)

|错误加载BuildConfig时出错:启动失败: script15010760392501179421923.groovy:1:无法解析类com.whatever.configuration.ConfigurationFilesManager  @第1行,第1列。    import com.whatever.configuration.ConfigurationFilesManager

任何帮助?提前谢谢。

1 个答案:

答案 0 :(得分:0)

您可以查看 Grails use config.properties value into BuildConfig.groovy

将config.properties替换为config.goorvy 然后你可以在BuildConfig中获得Config值 在2.5.6中测试

但是如果我们在config.groovy中定义一个配置,比如 `tomcatVersion =" 2.2.4"

build":tomcat:$ slurp.tomcatVersion"将变成":tomcat:" 2.2.4" " 它不适合格式

您可以使用另一种表达方式,例如
compile group: 'org.grails', name: 'tomcat', version: $slurp.tomcatVersion