开发者

Getting Checkstyle custom rule to work in Hudson/Jenkins

I'm having problems trying to get checkstyle to work properly in Hudson/Jenkins.

I created a custom checkstyle rule with very minimal rules in it (just to see if it works) and place it in some server:-

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

I have a parent pom that looks like this:-

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

The actual project will include the parent pom, like this:-

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

When I execute mvn clean site from Eclipse, it works just fine. Instead of seeing 1000+ checkstyle errors using the default config/sun_checks.xml, I'm getting just 27 checkstyle errors.

When I run it in Jenkins, for some reason, it is not picking up my custom checkstyle rule. I'm getting 1000+ checkstyle errors from Jenkins. I checked the "Console Output" log and I'm not seeing any errors/warnings on checkstyle. The executed maven command from Jenkins look like this:-

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

I'm hoping to be able to add -e or -X开发者_开发问答 option to see a more robust log, but I can't find a place to insert them in Jenkins.

How do I get my custom checkstyle rule to work with Hudson/Jenkins?

Thanks much.


You can add the -eand -X switch in the "Goals und Optionen" field.

Are you refering checkstyle from an external location? If so, maybe you can try adding checkstyle to your project in your VCS (when this works it might be a network problem). Adding checkstyle.xml to your VCS also has the benefit, that you have reproducibility of your builds (and the other benifits VCS have to offer).


I setup how Maven finds my checkstyle.xml configLocation differently

maybe that'll get Jenkins working.

Also if you create a standard job instead of a maven job on Jenkins you can still execute a maven goal and you can simply add parameters

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

Written up here:

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

source code here:

https://github.com/blundell/CreateYourOwnCheckStyleCheck

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜