java - 如何在 groovy 2.5 中使用 CodeNarc maven 插件?
问题描述
我正在使用 CodeNarc maven 插件来静态分析用 groovy 编写的测试。我想将库更新到更高版本,不幸的是 codeNarc maven 插件版本不适用于 groovy 2.5。你有什么解决办法吗?也许另一个插件?
从 pom.xml 中提取:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>codenarc-maven-plugin</artifactId>
<version>0.22-1</version>
<configuration>
<groovyVersion>2.5.8</groovyVersion>
<rulesetfiles>file:///${project.basedir}/../config/codenarc.groovy</rulesetfiles>
<testSourceRoots>${project.basedir}/src/test/groovy</testSourceRoots>
<maxPriority1Violations>0</maxPriority1Violations>
<maxPriority2Violations>0</maxPriority2Violations>
<maxPriority3Violations>0</maxPriority3Violations>
</configuration>
<executions>
<execution>
<phase>test-compile</phase>
<goals>
<goal>codenarc</goal>
</goals>
</execution>
</executions>
</plugin>
在验证期间显示错误:
[ERROR] Failure to find org.codehaus.groovy:groovy-all:jar:2.5.8 in https://maven.... was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
我认为这与此有关:
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.5.8</version>
<scope>runtime</scope>
<type>pom</type><!-- not jar!!! -->
</dependency>
解决方案
我可能有点晚了,但对于其他人稍后在 StackOverflow 上搜索...
我们使用了 CodeNarc Ant 任务(我们在父 POM 中有所有版本):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.codenarc</groupId>
<artifactId>CodeNarc</artifactId>
</dependency>
<dependency>
<groupId>org.gmetrics</groupId>
<artifactId>GMetrics</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
</dependencies>
<executions>
<execution>
<id>codenarc-checks</id>
<phase>process-classes</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<property name="compile_classpath"
refid="maven.compile.classpath" />
<taskdef name="codenarc"
classname="org.codenarc.ant.CodeNarcTask" />
<echo
message="Checking Groovy code with CodeNarc" />
<codenarc
ruleSetFiles="file:/some/path/to/ruleset.groovy">
<report type="xml">
<option name="outputFile"
value="${project.build.directory}/codenarcReport.xml" />
</report>
<fileset dir="${groovy.main.directory}">
<include name="**/*.groovy" />
</fileset>
</codenarc>
</target>
</configuration>
</execution>
</executions>
</plugin>
推荐阅读
- php - yii 获取 has_many 关系计数
- ios - XMPP 我需要在特定聊天对话中通过 XMPP Chat 发送打字状态
- python - Python中的Pyo;名称“服务器”未定义
- git - 无法在 git 自定义预接收挂钩中运行 git 命令
- arrays - 当过滤条件在预先存在的字符串中时使用 .Filter (TypeScript/Node.js)
- python - Python:请求和响应 401
- ios - 应用程序崩溃并出现错误:对象已被删除或无效
- java - 在 Java 中通过 id 搜索 SQL 中的记录
- smlnj - number_in_month 练习(比较两个列表)
- bash - wmctrl 不正确的调整大小和移动 - 取决于应用程序