天天看點

Jenkins checkstyle+ant對代碼規範進行檢測(學習筆記二十八)

1.目标

  通過jenkins使用checkstyle對代碼進行規範檢查并生成html報告。

  建構采用shell。

2.環境

checkstyle5.7

(如果是Linux版本選用

tar.gz格式

apache-ant-1.9.9

①其他預設環境(如jdk)

同前

②checkstyle沒有選擇最新版7.6.1是因為7.6.1版本沒有将xml格式的報告轉換為html報告的xsl檔案。

③ant版本不宜選擇太高,因為高版本可能需要JDK8+的支援。

④jenkins checkstyle插件主要是用于出版checkstyle報告,這裡不涉及。

3.前置工作

  3.1 安裝ant及checkstyle。

  3.2 編寫ant腳本執行checkstyle建構。

Jenkins checkstyle+ant對代碼規範進行檢測(學習筆記二十八)
Jenkins checkstyle+ant對代碼規範進行檢測(學習筆記二十八)
Jenkins checkstyle+ant對代碼規範進行檢測(學習筆記二十八)

每個checkstyle作業都應該建立一個類似的ant腳本,隻需要更改作業源碼路徑(2處)。

4.jenkins配置

  建立一個自由風格的job,配置如下:

Jenkins checkstyle+ant對代碼規範進行檢測(學習筆記二十八)

這裡源碼使用了碼雲的

zheng項目

,直接放到了該作業工作區的src目錄之下。

5.建構結果

在工作區中建立了一個checkstyle_report目錄,目錄中生成了checkstyle_report.xml和checkstyle_report.html檔案。

Jenkins checkstyle+ant對代碼規範進行檢測(學習筆記二十八)
Jenkins checkstyle+ant對代碼規範進行檢測(學習筆記二十八)

   html格式的報告内容如下:

Jenkins checkstyle+ant對代碼規範進行檢測(學習筆記二十八)