简体   繁体   English

Gradle中使用CodeNarc生成多种报告类型

[英]Generate multiple report types using CodeNarc in Gradle

I want to generate both HTML and console report in CodeNarc in Gradle.我想在 Gradle 的 CodeNarc 中同时生成 HTML 和控制台报告。

My build.gradle :我的build.gradle

apply plugin: 'codenarc'
...
codenarc {
    toolVersion = '0.24.1'
    configFile = file('config/codenarc/codenarc.groovy')
    reportFormat = 'html'
}

This works fine, but I'd like also to have report displayed on console, as right now only link to HTML is displayed there.这工作正常,但我也希望在控制台上显示报告,因为现在那里只显示指向 HTML 的链接。 How can I request multiple report types?如何请求多种报告类型?

Instead of running a second task to generate another report, you could make the following change to add another report format.您可以进行以下更改以添加另一种报告格式,而不是运行第二个任务来生成另一个报告。 Then grab one of the files and write it to the console.然后抓取其中一个文件并将其写入控制台。 (You could just grab the HTML or XML report and write that to the console, but it may be hard to read without some formatting.) (您可以直接获取 HTML 或 XML 报告并将其写入控制台,但如果没有一些格式,可能很难阅读。)

Note: The reports closure will get you reports in different formats.注意: reports关闭将为您提供不同格式的报告。 The doLast will print the output of one of those reports to the console. doLast会将这些报告之一的输出打印到控制台。 If you do not need the console output, you can remove the doLast closure.如果不需要控制台输出,可以删除doLast闭包。

I would suggest changing your task like this:我建议像这样改变你的任务:

task codenarcConsoleReport {
    doLast {
        println file("${codenarc.reportsDir}/main.txt").text
    }
}
codenarcMain {
    finalizedBy codenarcConsoleReport
    reports {
        text.enabled = true
        html.enabled = true
        xml {
            enabled =  true
            destination = file("${codenarc.reportsDir}/customFileName.xml")
        }
    }
}

Note: This will not cause your task to run twice.注意:这不会导致您的任务运行两次。

In newer versions of Gradle (7+) I get a deprecation warning on:在 Gradle (7+) 的较新版本中,我收到了弃用警告:

reports {
    html.enabled = true
    xml.enabled = true
}

The format has changed to (for enabling html and xml reports)格式已更改为(用于启用 html 和 xml 报告)

reports {
    html.required = true
    xml.required = true
}

Best way I can think of is to create a separate task:我能想到的最好方法是创建一个单独的任务:

task codeNarcConsole(type: CodeNarc) {
  // other config
  reportFormat = 'console'
}

check.dependsOn('codeNarcConsole')

Not ideal, but workable.不理想,但可行。 You could also post to Gradle Bugs about this to get it improved.您也可以将有关此问题的信息发布到Gradle Bugs以对其进行改进。

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

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