我想做什么?
我想告诉 CodeNarc 它应该扫描/分析哪些文件夹/目录。
我在官方网站 ( http://codenarc.sourceforge.net/ ) 或 gradle 插件文档 ( https://docs.gradle.org/current/userguide/codenarc_plugin.html )上找不到任何相关信息。
我的研究结果:
我发现的唯一相关内容是 grails CodeNarc 插件文档 ( https://grails.org/plugin/codenarc )。它说您可以配置 CodeNarc 分析哪些源文件。但这似乎只适用于 grails CodeNarc 插件而不是 gradle 版本。
gradle CodeNarc 文档描述了 3 个任务,其中之一具有以下内容:
codenarcSourceSet — CodeNarc
Runs CodeNarc against the given source set’s Java source files
根据描述,我认为我可以用它做点什么。但是当我查找所有任务时,我的 gradle 项目只有“codenarcMain”和“codenarcTest”。
我的设置:
我的 gradle 项目具有以下结构:
.git
-> ...
.gradle
-> ...
config
-> codenarc -> MyRuleset.groovy
gradle
-> ...
src
-> main
-> groovy -> ...
-> ressources
-> test
-> groovy -> ...
-> ressources
vars
-> ...
.gitignore
build.gradle
gradlew
gradlew.bat
ReadMe.txt
settings.gradle
我的 build.gradle 看起来像这样:
plugins {
// Apply the groovy plugin to add support for Groovy
id 'groovy'
id 'codenarc'
}
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
maven { url "http://repo.jenkins-ci.org/releases/" }
maven { url "http://central.maven.org/maven2/" }
}
dependencies {
// https://mvnrepository.com/artifact/org.jenkins-ci.main/jenkins-core
compile group: 'org.jenkins-ci.main', name: 'jenkins-core', version: '2.179'
// https://mvnrepository.com/artifact/org.jenkins-ci.plugins/cloudbees-folder
compile 'org.jenkins-ci.plugins:cloudbees-folder:5.3@jar'
// https://mvnrepository.com/artifact/org.jenkins-ci.plugins.workflow/workflow-api
compile 'org.jenkins-ci.plugins.workflow:workflow-api:2.35@jar'
// https://mvnrepository.com/artifact/org.jenkins-ci.plugins.workflow/workflow-job
compile 'org.jenkins-ci.plugins.workflow:workflow-job:2.32@jar'
// https://mvnrepository.com/artifact/com.cloudbees/groovy-cps
compile group: 'com.cloudbees', name: 'groovy-cps', version: '1.28'
// https://mvnrepository.com/artifact/org.codenarc/CodeNarc
codenarc group: 'org.codenarc', name: 'CodeNarc', version: '1.1'
// Use the latest Groovy version for building this library
implementation 'org.codehaus.groovy:groovy-all:2.5.6'
// Use the awesome Spock testing and specification framework
testImplementation 'org.spockframework:spock-core:1.2-groovy-2.5'
}
codenarc {
configFile = file("${project.projectDir}/config/codenarc/MyRuleset.groovy")
reportFormat = 'html'
reportsDir = file("$buildDir/reports/StaticCodeAnalysis")
maxPriority1Violations = 0
maxPriority2Violations = 0
maxPriority3Violations = 0
}
具体目标:
我基本上希望 CodeNarc 也扫描“vars”文件夹/目录中的脚本。但它似乎只在 src/main/groovy 和 src/test/groovy 中这样做。我也不确切知道默认路径是什么,因为我没有在文档中找到它。