【问题标题】:Getting Checkstyle custom rule to work in Hudson/Jenkins让 Checkstyle 自定义规则在 Hudson/Jenkins 中工作
【发布时间】:2011-09-15 16:39:54
【问题描述】:

我在尝试让 checkstyle 在 Hudson/Jenkins 中正常工作时遇到问题。

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

<?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>

我有一个看起来像这样的父 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>

实际项目将包含父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>

当我从 Eclipse 执行 mvn clean site 时,它工作得很好。而不是使用默认的config/sun_checks.xml 看到 1000 多个 checkstyle 错误,我只得到 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...
...

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

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

非常感谢。

【问题讨论】:

    标签: java maven-2 hudson jenkins checkstyle


    【解决方案1】:

    我设置了 Maven 如何以不同的方式找到我的 checkstyle.xml configLocation

    也许这会让 Jenkins 工作。

    此外,如果您在 Jenkins 上创建标准作业而不是 maven 作业,您仍然可以执行 maven 目标并且您可以简单地添加参数

    <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/xsd/maven-4.0.0.xsd">
    
      ...
    
      <properties>
        <checkstyle.config.location>http://server/checkstyle.xml</checkstyle.config.location>
      </properties>
    
      <build>
        ...
    
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>2.9.1</version>
          </plugin>
        </plugins>
      </build>
    
    </project>
    

    写在这里:

    http://blog.blundell-apps.com/create-your-own-checkstyle-check/

    这里有源代码:

    https://github.com/blundell/CreateYourOwnCheckStyleCheck

    【讨论】:

      【解决方案2】:

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

      您是从外部位置引用 checkstyle 吗?如果是这样,也许您可​​以尝试在您的 VCS 中将 checkstyle 添加到您的项目中(当这可行时,它可能是网络问题)。将 checkstyle.xml 添加到您的 VCS 也有好处,您可以重现您的构建(以及 VCS 必须提供的其他好处)。

      【讨论】:

        猜你喜欢
        • 2013-08-17
        • 1970-01-01
        • 1970-01-01
        • 2013-09-07
        • 1970-01-01
        • 2013-09-27
        • 2020-06-02
        • 2018-04-06
        • 1970-01-01
        相关资源
        最近更新 更多