2017-08-17 119 views
0

我已經寫了下面的pom.xml文件,它應該創建一個checkstyle報告/傾向圖,並在出現checkstyle警告時中止構建前置操作。Jenkins/Maven checkstyle:check in pom.xml does not work

<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"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>test</groupId> 
    <artifactId>test</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>test</name> 
    <url>http://maven.apache.org</url> 

    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 
    </dependencies> 
    <reporting> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-checkstyle-plugin</artifactId> 
     <version>2.8</version> 
     <reportSets> 
      <reportSet> 
       <reports> 
       <report>checkstyle</report> 
       </reports> 
      </reportSet> 
      </reportSets> 
      <configuration> 
      <configLocation>https://dustplanet.de/checkstyle.xml</configLocation> 
     </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-project-info-reports-plugin</artifactId> 
      <version>2.7</version> 
     </plugin> 
    </plugins> 
    </reporting> 
    <build> 
    <pluginManagement> 
     <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugin</groupId> 
      <artifactId>maven-checkstyle-plugin</artifactId> 
      <version>2.17</version> 
      <executions> 
      <execution> 
       <phase>validate</phase> 
       <goals> 
        <goal>check</goal> 
       </goals> 
       <configuration> 
        <consoleOutput>true</consoleOutput> 
        <failsOnError>true</failsOnError> 
        <failOnViolation>true</failOnViolation> 
       </configuration> 
      </execution> 
     </executions> 
     </plugin> 
     </plugins> 
     </pluginManagement> 
     <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-checkstyle-plugin</artifactId> 
     <version>2.17</version> 
     </plugin> 
    </plugins> 
    </build> 

</project> 

的問題是,如果我建立與詹金斯Maven項目和clean install項目被建造,但的CheckStyle插件沒有得到執行這Maven目標。所以我用​​。通過site已經創建了一個報告和一個趨勢圖,但構建過程仍然沒有停止。之後,我使用clean install site checkstyle:check -Dcheckstyle.config.location="https://dustplanet.de/checkstyle.xml",這樣我的構建過程失敗了,但分析結果以及趨勢圖並未顯示任何checkstyle錯誤,儘管已在目標目錄中創建了一個報告,並且始終在該複選框中進行分析作業的配置被激活。這是最後一次構建的控制檯輸出:

Started by timer 
[EnvInject] - Loading node environment variables. 
Building in workspace /var/lib/jenkins/workspace/MavenProject2 
> git rev-parse --is-inside-work-tree # timeout=10 
Fetching changes from the remote Git repository 
> git config remote.origin.url [email protected]:SysKit/SYSKIT.git # timeout=10 
Fetching upstream changes from [email protected]:SysKit/SYSKIT.git 
> git --version # timeout=10 
using GIT_SSH to set credentials 
> git fetch --tags --progress [email protected]:SysKit/SYSKIT.git +refs/heads/*:refs/remotes/origin/* +refs/merge-requests/*/head:refs/remotes/origin/merge-requests/* 
> git rev-parse origin/master^{commit} # timeout=10 
Checking out Revision 11d0f4105661346b7577fa223fe0f4063572fb99 (origin/master) 
Commit message: "test" 
> git config core.sparsecheckout # timeout=10 
> git checkout -f 11d0f4105661346b7577fa223fe0f4063572fb99 
> git rev-list 11d0f4105661346b7577fa223fe0f4063572fb99 # timeout=10 
Parsing POMs 
Established TCP socket on 35703 
[test] $ java -cp /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven33-agent-1.11.jar:/opt/maven/boot/plexus-classworlds-2.5.2.jar:/opt/maven/conf/logging jenkins.maven3.agent.Maven33Main /opt/maven /var/cache/jenkins/war/WEB-INF/lib/remoting-3.7.jar /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven33-interceptor-1.11.jar /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.11.jar 35703 
<===[JENKINS REMOTING CAPACITY]===>channel started 
Executing Maven: -B -f /var/lib/jenkins/workspace/MavenProject2/test/pom.xml site clean install checkstyle:check -Dcheckstyle.config.location=https://dustplanet.de/checkstyle.xml 
[INFO] Scanning for projects... 
[INFO]                   
[INFO] ------------------------------------------------------------------------ 
[INFO] Building test 0.0.1-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- maven-site-plugin:3.3:site (default-site) @ test --- 
[INFO] configuring report plugin org.apache.maven.plugins:maven-checkstyle-plugin:2.8 
[INFO] configuring report plugin org.apache.maven.plugins:maven-project-info-reports-plugin:2.7 
[INFO] Relativizing decoration links with respect to project URL: http://maven.apache.org 
[INFO] Rendering site with org.apache.maven.skins:maven-default-skin:jar:1.0 skin. 
[INFO] Generating "Checkstyle" report --- maven-checkstyle-plugin:2.8 
[INFO] 
[INFO] There are 1 checkstyle errors. 
[WARNING] Unable to locate Source XRef to link to - DISABLED 
[INFO] Generating "About" report --- maven-project-info-reports-plugin:2.7 
[INFO] Generating "Plugin Management" report --- maven-project-info-reports-plugin:2.7 
[INFO] Generating "Distribution Management" report --- maven-project-info-reports-plugin:2.7 
[INFO] Generating "Dependency Information" report --- maven-project-info-reports-plugin:2.7 
[INFO] Generating "Source Repository" report --- maven-project-info-reports-plugin:2.7 
[INFO] Generating "Mailing Lists" report --- maven-project-info-reports-plugin:2.7 
[INFO] Generating "Issue Tracking" report --- maven-project-info-reports-plugin:2.7 
[INFO] Generating "Continuous Integration" report --- maven-project-info-reports-plugin:2.7 
[INFO] Generating "Project Plugins" report --- maven-project-info-reports-plugin:2.7 
[INFO] Generating "Project License" report --- maven-project-info-reports-plugin:2.7 
[INFO] Generating "Project Team" report --- maven-project-info-reports-plugin:2.7 
[INFO] Generating "Project Summary" report --- maven-project-info-reports-plugin:2.7 
[INFO] Generating "Dependencies" report --- maven-project-info-reports-plugin:2.7 
[CHECKSTYLE] Parsing file /var/lib/jenkins/workspace/MavenProject2/test/target/checkstyle-result.xml 
[CHECKSTYLE] Successfully parsed file /var/lib/jenkins/workspace/MavenProject2/test/target/checkstyle-result.xml of module test with 1 unique warning and 0 duplicates. 
[CHECKSTYLE] Computing warning deltas based on reference build #226 
[JENKINS] Archiving site from /var/lib/jenkins/workspace/MavenProject2/test/target/site to /var/lib/jenkins/jobs/MavenProject2/site 
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ test --- 
[INFO] Deleting /var/lib/jenkins/workspace/MavenProject2/test/target 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test --- 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/MavenProject2/test/src/main/resources 
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test --- 
[INFO] Changes detected - recompiling the module! 
[INFO] Compiling 1 source file to /var/lib/jenkins/workspace/MavenProject2/test/target/classes 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ test --- 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/MavenProject2/test/src/test/resources 
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ test --- 
[INFO] Changes detected - recompiling the module! 
[INFO] Compiling 1 source file to /var/lib/jenkins/workspace/MavenProject2/test/target/test-classes 
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ test --- 
[INFO] Surefire report directory: /var/lib/jenkins/workspace/MavenProject2/test/target/surefire-reports 

------------------------------------------------------- 
T E S T S 
------------------------------------------------------- 
Running test.test.AppTest 
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.052 sec 

Results : 

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 

[JENKINS] Recording test results 
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ test --- 
[INFO] Building jar: /var/lib/jenkins/workspace/MavenProject2/test/target/test-0.0.1-SNAPSHOT.jar 
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ test --- 
[INFO] Installing /var/lib/jenkins/workspace/MavenProject2/test/target/test-0.0.1-SNAPSHOT.jar to /var/lib/jenkins/.m2/repository/test/test/0.0.1-SNAPSHOT/test-0.0.1-SNAPSHOT.jar 
[INFO] Installing /var/lib/jenkins/workspace/MavenProject2/test/pom.xml to /var/lib/jenkins/.m2/repository/test/test/0.0.1-SNAPSHOT/test-0.0.1-SNAPSHOT.pom 
[INFO] 
[INFO] --- maven-checkstyle-plugin:2.17:check (default-cli) @ test --- 
[INFO] There is 1 error reported by Checkstyle 6.11.2 with https://dustplanet.de/checkstyle.xml ruleset. 
[ERROR] src/main/java/test/test/App.java:[11,43] (whitespace) WhitespaceAround: '{' is not preceded with whitespace. 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 36.200 s 
[INFO] Finished at: 2017-08-17T17:47:53+02:00 
[INFO] Final Memory: 44M/106M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check (default-cli) on project test: You have 1 Checkstyle violation. -> [Help 1] 
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 
[ERROR] Re-run Maven using the -X switch to enable full debug logging. 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles: 
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException 
[JENKINS] Archiving /var/lib/jenkins/workspace/MavenProject2/test/pom.xml to test/test/0.0.1-SNAPSHOT/test-0.0.1-SNAPSHOT.pom 
[JENKINS] Archiving /var/lib/jenkins/workspace/MavenProject2/test/target/test-0.0.1-SNAPSHOT.jar to test/test/0.0.1-SNAPSHOT/test-0.0.1-SNAPSHOT.jar 
Not sending mail to unregistered user [email protected] 
An attempt to send an e-mail to empty list of recipients, ignored. 
channel stopped 
[ANALYSIS-COLLECTOR] Computing warning deltas based on reference build #226 
Not sending mail to unregistered user [email protected] 
An attempt to send an e-mail to empty list of recipients, ignored. 
Finished: FAILURE 

有人知道我做錯了什麼嗎?

編輯1 好吧,我現在知道,構建序列中的checkstyle插件不能正常工作,因爲我現在得到這個警告。

[INFO] Scanning for projects... 
[WARNING] The POM for org.apache.maven.plugin:maven-checkstyle-plugin:jar:2.17 is missing, no dependency information available 
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugin:maven-checkstyle-plugin:2.17: Plugin org.apache.maven.plugin:maven-checkstyle-plugin:2.17 or one of its dependencies could not be resolved: Failure to find org.apache.maven.plugin:maven-checkstyle-plugin:jar:2.17 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced 
[INFO]                   
[INFO] ------------------------------------------------------------------------ 
[INFO] Building test 0.0.1-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[WARNING] The POM for org.apache.maven.plugin:maven-checkstyle-plugin:jar:2.17 is missing, no dependency information available 
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugin:maven-checkstyle-plugin:2.17: Plugin org.apache.maven.plugin:maven-checkstyle-plugin:2.17 or one of its dependencies could not be resolved: Failure to find org.apache.maven.plugin:maven-checkstyle-plugin:jar:2.17 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced 

他們只有當我把插件的CheckStyle在構建順序發生,在報告序列中的CheckStyle插件的正常工作。我如何解決這個警告?

EDIT 2

確定的問題是,我忘了插件後的 「s」 在<groupId>org.apache.maven.plugin</groupId>。該插件仍然沒有執行,但我現在將該構建標記爲不穩定或失敗,而不是jenkins中的checkstyle插件。儘管如此,我應該儘快採取這種方式來幫助。

+0

我不知道是什麼你希望實現,但是你的構建過程中斷會導致checkstyle錯誤:[[ERROR] src/main/java/test/test/App.java:[11,43](空格)WhitespaceAround:'{'與空白....'..? – khmarbaise

+0

我想實現構建過程失敗,如果發生checkstile錯誤,但也是我的checkstyle趨勢圖以及詹金斯的分析報告得到正確更新。現在我只能實現構建過程中斷或趨向圖得到正確更新,但不能同時進行。對不起,如果很難理解我,即時新jenkins和maven,我的英語也不是最好的。 – seb2704

回答

1

你需要添加maven-checkstyle-plugin報告插件安裝到您的pom.xml,您可以使用下面的插件:

<project> 
    ... 
    <reporting> 
     <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-checkstyle-plugin</artifactId> 
      <version>2.17</version> 
      <reportSets> 
      <reportSet> 
       <reports> 
       <report>checkstyle</report> 
       </reports> 
      </reportSet> 
      </reportSets> 
     </plugin> 
     </plugins> 
    </reporting> 
    ... 
</project> 

更多可以參考以下鏈接:

https://maven.apache.org/plugins/maven-checkstyle-plugin/usage.html

+0

mhm我已經在上面的pom.xml中做了這個。問題不在於報告沒有創建,問題是如果構建過程中斷,jenkins的分析報告和圖形趨勢不會得到正確更新,並且看起來像部分中的checkstyle插件無法正常工作。 – seb2704