2011-06-15 51 views
5

我在嘗試讓checkstyle在Hudson/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> 

我有一個看起來像這樣的父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> 

當我execu來自Eclipse的te mvn clean site,它工作得很好。使用默認的config/sun_checks.xml而不是看到1000多個checkstyle錯誤,我只得到27個checkstyle錯誤。

當我在Jenkins運行它時,出於某種原因,它沒有選擇我自定義的checkstyle規則。我得到了Jenkins的1000多個checkstyle錯誤。我檢查了「控制檯輸出」日誌,我沒有看到任何關於checkstyle的錯誤/警告。從詹金斯的執行行家命令是這樣的: -

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

我希望能夠添加-e-X選項看到一個更強大的日誌,但我不能找到將其插入到一個地方詹金斯。

如何讓我的自定義檢查式規則與哈德遜/詹金斯一起工作?

非常感謝。

回答

0

您可以在「目標和選項」字段中添加-e-X開關。

您是否從外部位置引用checkstyle?如果是這樣,也許你可以嘗試添加checkstyle到你的VCS中的項目(當它工作時,它可能是一個網絡問題)。將checkstyle.xml添加到您的VCS中也有好處,您擁有可重複的構建(以及VCS必須提供的其他利益)。

0

我設置的Maven如何找到我的checkstyle.xml configLocation不同

也許這會得到詹金斯工作。

此外,如果您創建一個標準的工作,而不是一個行家的工作對詹金斯你仍然可以執行的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