让Checkstyle自定义规则在Hudson/Jenkins中工作

lim*_*imc 5 java maven-2 hudson checkstyle jenkins

我在试图让checkstyle在Hudson/Jenkins中正常工作时遇到了问题.

我创建了一个自定义的checkstyle规则,其中包含非常少的规则(只是为了查看它是否有效)并将其放在某个服务器中: -

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
    <module name="RegexpSingleline">
        <property name="format" value="\s+$" />
        <property name="minimum" value="0" />
        <property name="maximum" value="0" />
        <property name="message" value="Line has trailing spaces." />
    </module>
</module>
Run Code Online (Sandbox Code Playgroud)

我有一个看起来像这样的父pom: -

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>a.b</groupId>
    <artifactId>c</artifactId>
    <packaging>pom</packaging>
    <version>1.0</version>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <configLocation>http://server/checkstyle.xml</configLocation>
                </configuration>
            </plugin>
        </plugins>
    </reporting>
</project>
Run Code Online (Sandbox Code Playgroud)

实际项目将包括父pom,如下所示: -

<?xml version="1.0" encoding="UTF-8"?>
<project>
    <parent>
        <groupId>a.b</groupId>
        <artifactId>c</artifactId>
        <version>1.0</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <groupId>some</groupId>
    <artifactId>project</artifactId>
    <packaging>jar</packaging>
    <version>1.0</version>

    ...
</project>
Run Code Online (Sandbox Code Playgroud)

当我mvn clean site从Eclipse 执行时,它工作得很好.我没有看到使用默认值的1000多个checkstyle错误config/sun_checks.xml,而是只得到27个checkstyle错误.

当我在Jenkins中运行它时,由于某种原因,它没有拿起我的自定义checkstyle规则.我从Jenkins那里得到了1000多个checkstyle错误.我检查了"控制台输出"日志,我没有在checkstyle上看到任何错误/警告.Jenkins执行的maven命令如下所示: -

<===[HUDSON REMOTING CAPACITY]===>channel started
Executing Maven:  -B -f D:\hudson\jobs\test\workspace\pom.xml clean site
[INFO] Scanning for projects...
...
Run Code Online (Sandbox Code Playgroud)

我希望能够添加-e-X选项以查看更强大的日志,但我找不到在Jenkins中插入它们的位置.

如何让我的自定义checkstyle规则与Hudson/Jenkins一起使用?

非常感谢.

Dag*_*Dag 0

您可以在“目标和选项”字段中添加-e和开关。-X

您是从外部位置引用 checkstyle 吗?如果是这样,也许您可​​以尝试将 checkstyle 添加到 VCS 中的项目中(当此方法有效时,可能是网络问题)。将 checkstyle.xml 添加到您的 VCS 中还有一个好处,即您的构建具有可重复性(以及 VCS 必须提供的其他好处)。