简体   繁体   English

如何为多项目Gradle构建创建单个CodeNarc报告

[英]How create a single CodeNarc report for a multiple-project Gradle build

I have a Gradle multi-projects build where each subproject creates its own CodeNarc report. 我有一个Gradle多项目构建,其中每个子项目都创建了自己的CodeNarc报告。

Is it possibile to create a single CodeNarc analysis report for all the projects in my build instead of a separate report for each of them? 是否可以为构建中的所有项目创建单个CodeNarc分析报告,而不是为每个项目创建单独的报告?

You can create your own CodeNarc task and configure it with the sourcesets of all its subprojects as follows. 您可以创建自己的CodeNarc任务,并使用其所有子项目的源集对其进行配置,如下所示。

task supernarc(type: CodeNarc) {
  def allGroovySourceDirs = subprojects.collect { Project p -> p.sourceSets.main.allGroovy.getSrcDirs() }.flatten()

  allGroovySourceDirs.each {
    source(it)
  }

  // BTW, if you know you have some violations and don't want the builds to fail because of too many violations, you can increase the threshold as follows
  maxPriority1Violations = 5
  maxPriority2Violations = 5
  maxPriority3Violations = 5

} }

I created this sample on Github for you so you could see a project using it. 我为您在Github上创建了此示例,因此您可以看到一个使用它的项目。

Does that help? 有帮助吗?

Cheers Kon 干杯

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

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