我试图将CodeNarc集成到一个基于maven的项目中,并且遇到了一些问题。我想使用自定义规则集,当规则被违反时,我希望我的maven构建失败。
如何配置代码弧,以便在运行以下代码时违反规则会导致失败?
mvn clean install此外,在POM中配置CodeNarc的文档没有解释如何引用我的自定义规则集。有什么好的建议吗?谢谢!
当我使用下面的配置运行mvn干净安装时(根据我的规则集,我有一个带有公然违规的groovy文件)
我的建筑成功了。:(
我试着引用我自己的规则,没有任何违规行为发生。我拿走了POM中的一个规则文件属性,它开始产生违规行为。(但我没有机会选择自己的)
有人知道如何让它实际读取自定义规则集文件吗?我尝试使用xml和groovy。
下面是我的POM中的规则集和插件配置:
<ruleset xmlns="http://codenarc.org/ruleset/1.0";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://codenarc.org/ruleset/1.0 http://codenarc.org/ruleset-schema.xsd";
xsi:noNamespaceSchemaLocation="http://codenarc.org/ruleset-schema.xsd">;
<description>Dummy rule set</description>
<rule class='org.codenarc.rule.formatting.SpaceAfterIf'>
<property name='priority' value='1'/>
</rule>
<rule class='org.codenarc.rule.basic.EmptyIfStatement'>
<property name='priority' value='1'/>
</rule>
</ruleset>我在POM中引用了如下规则:
org.codehaus.mojo代码-maven-plugin 0.18-1 ${basedir}/src/test/groovy ${basedir}/ rulesets/rueset.xml${basedir}/ execution1安装代码弧
发布于 2014-09-25 14:12:05
一段时间前我也在为同样的事情而挣扎。我记得正确地使用maven运行是可能的,但是我没有这个配置。为什么?因为CodeNarc需要编译源代码来执行某些规则。但是codenarc插件没有通过类路径,编译失败了。
因此,我选择了不同的方法,将CodeNarc作为带有ant任务的测试源。看上去:
import spock.lang.Specification
class GroovyCodeNarcStaticAnalysisRunner extends Specification {
private static final GROOVY_FILES = '**/*.groovy'
private static final ANALYSIS_SCOPE = 'src/main/groovy'
private static final RULESET_LOCATION = 'file:tools/static-analysis/codenarc.xml'
private static final HTML_REPORT_FILE = 'target/codenarc-result.html'
private static final XML_REPORT_FILE = 'target/codenarc-result.xml'
def 'Groovy code should meet coding standards'() {
given:
def ant = new AntBuilder()
ant.taskdef(name: 'codenarc', classname: 'org.codenarc.ant.CodeNarcTask')
expect:
ant.codenarc(
ruleSetFiles: RULESET_LOCATION,
maxPriority1Violations: 0,
maxPriority2Violations: 0,
maxPriority3Violations: 0)
{
fileset(dir: ANALYSIS_SCOPE) {
include(name: GROOVY_FILES)
}
report(type: 'text') {
option(name: 'writeToStandardOut', value: true)
}
report(type: 'xml') {
option(name: 'outputFile', value: XML_REPORT_FILE)
}
report(type: 'html') {
option(name: 'outputFile', value: HTML_REPORT_FILE)
}
}
}
}你不需要为此使用史波克的Specification。任何测试跑步者都可以。在maven端,只需使用范围测试配置CodeNarc依赖即可。
https://stackoverflow.com/questions/25967040
复制相似问题