简体   繁体   English

在Gradle中配置CodeNarc

[英]Configuring CodeNarc in Gradle

I am trying to wrap my head around using CodeNarc inside of Gradle . 我试图在Gradle中使用CodeNarc

According to the CodeNarc docs, my project needs to have a config/codenarc/codenarc.xml config file defined. 根据CodeNarc文档,我的项目需要定义config/codenarc/codenarc.xml配置文件。 But then I see plenty of example config files (such as this StarterRuleSet ) that seem to use a Groovy DSL. 但后来我看到很多示例配置文件(例如这个StarterRuleSet )似乎使用了Groovy DSL。

So I ask: 所以我问:

  1. Is it possible to use a Groovy DSL, and if so what does the name of the file have to be, where does it have to be located in my project, and how do I wire it up to my Gradle build?; 是否可以使用Groovy DSL,如果是这样,文件的名称必须是什么,它必须在我的项目中的哪个位置,以及如何将其连接到我的Gradle构建? and
  2. Where is the documentation on the Groovy DSL?; Groovy DSL上的文档在哪里? and
  3. By default, CodeNarc outputs a report called main.html ; 默认情况下,CodeNarc会输出一个名为main.html的报告; how could I change the name of this file to, say, codenarc.html ? 我怎么能把这个文件的名称更改为,例如, codenarc.html

It looks like in your build.gradle you can just put: 它看起来像你的build.gradle你可以放:

codenarc {
    toolVersion = "0.20"
}

codenarcMain {
    configFile = rootProject.file("path/to/CodeNarcMain.groovy")
}

codenarcTest {
    configFile = rootProject.file("path/to/CodeNarcTest.groovy")
}

Where the file names ( CodeNarcMain , CodeNarcTest ) are whatever you want them to be. 文件名( CodeNarcMainCodeNarcTest )是您想要的任何名称。

Groovy DSL documentation is here. Groovy DSL文档就在这里。 If you need to configure a specific rule, look it up in the documentation and if the rule has public properties that it exposes, they'll be listed in a table under the specific rule's documentation. 如果需要配置特定规则,请在文档中查找,如果规则具有公开的属性,则它们将列在特定规则文档下的表中。

And it looks like you can only change the report file format (HTML, XML, text, console) but not the actual file name produced. 看起来您只能更改报告文件格式 (HTML,XML,文本,控制台),而不能更改生成的实际文件名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM