[英]Getting Checkstyle custom rule to work in 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>
當我從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一起使用?
非常感謝。
我設置了Maven如何以不同方式找到checkstyle.xml configLocation
也許這會讓詹金斯工作。
此外,如果您在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/
源代碼在這里:
您可以在“目標和選項”字段中添加-e
和-X
開關。
你是從外部位置推薦checkstyle嗎? 如果是這樣,也許你可以嘗試在你的VCS中為你的項目添加checkstyle(當它工作時它可能是一個網絡問題)。 將checkstyle.xml添加到VCS還有一個好處,即您具有構建的可重復性(以及VCS必須提供的其他優點)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.