简体   繁体   English

如何在 groovy 2.5 中使用 CodeNarc maven 插件?

[英]How to use CodeNarc maven plugin with groovy 2.5?

I'm using CodeNarc maven plugin to static analyze tests written in groovy.我正在使用 CodeNarc maven 插件来静态分析用 groovy 编写的测试。 I want to update libraries to higher version and unfortunately codeNarc maven plugin version is not working with groovy 2.5.我想将库更新到更高版本,不幸的是 codeNarc maven 插件版本不适用于 groovy 2.5。 Do you have any solution for that?你有什么解决办法吗? Maybe another plugin?也许另一个插件?

Extract from pom.xml:从 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>

during verify shows error:在验证期间显示错误:

[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

I think it is connected with that:我认为与此有关:

                <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-all</artifactId>
                    <version>2.5.8</version>
                    <scope>runtime</scope>
                    <type>pom</type><!-- not jar!!! -->
                </dependency>

I may be a bit late for this, but for others searching later on StackOverflow...我可能有点晚了,但是对于稍后在 StackOverflow 上搜索的其他人...

We used the CodeNarc Ant Task (we have all the versions in parent POMs):我们使用了 CodeNarc Ant Task(我们在父 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>

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

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