【问题标题】:Externalized BuildConfig in GrailsGrails 中的外部化 BuildConfig
【发布时间】:2013-01-16 20:45:06
【问题描述】:

我们可以通过指定一个配置脚本类来为Config.groovy 加载不同的配置文件。 Externalized Configuration:

grails.config.locations = [com.my.app.MyConfig]

可以为BuildConfig.groovy做类似的事情吗?

我想将 CodeNarc 配置放在另一个配置文件中。由于它使用 Groovy 的 ConfigSlurper 语法,我尝试合并配置对象,但不起作用。

def config = new ConfigSlurper().parse(..)    
this.merge(config)

有什么不同的技巧吗?

【问题讨论】:

  • 找到这个gist 可能对你有帮助。
  • 这听起来像是 CodeNarc 错误 - 您应该能够只定义保存此配置的位置,而不是污染 BuildConfig
  • @Sérgio:这是一个很棒的要点 :)

标签: grails configuration config buildconfig


【解决方案1】:

你不需要那样做。

Codenarc 插件可让您在外部保留您的 codenarc 配置。看这里 http://grails.org/plugin/codenarc#Configuring The Codenarc Properties

这里包含一个我在BuildConfig.groovy 中的示例代码设置

codenarc.processTestUnit = false
codenarc.processTestIntegration = false
codenarc.processViews = true
codenarc.propertiesFile = 'grails-app/conf/codenarc.properties'
codenarc.ruleSetFiles = [
        "rulesets/basic.xml",
        "rulesets/braces.xml",
        "rulesets/grails.xml",
        "rulesets/groovyism.xml",
]

在这里,我们还定义了一个外部codenarc.properties 文件,我们使用它来打开/关闭每个包含的规则集中的部分规则。此codenarc.properties 文件内容的示例包含在此处:

# some gsp's MUST have embedded CSS and/or embedded Javascript which requires the use of semicolons.
UnnecessarySemicolon.doNotApplyToFileNames = *.gsp
# we're not going to enforce these
UnnecessaryGString.enabled = false
UnnecessaryReturnKeyword.enabled = false

因此,您可以避免使用 Tomas 提到的不需要的东西污染您的 BuildConfig。

希望这会有所帮助。

汤姆

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-11
    • 1970-01-01
    • 2010-11-01
    • 2014-08-07
    相关资源
    最近更新 更多