我已经写了下面的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插件。尽管如此,我应该尽快采取这种方式来帮助。
我不知道是什么你希望实现,但是你的构建过程中断会导致checkstyle错误:[[ERROR] src/main/java/test/test/App.java:[11,43](空格)WhitespaceAround:'{'与空白....'..? – khmarbaise
我想实现构建过程失败,如果发生checkstile错误,但也是我的checkstyle趋势图以及詹金斯的分析报告得到正确更新。现在我只能实现构建过程中断或趋向图得到正确更新,但不能同时进行。对不起,如果很难理解我,即时新jenkins和maven,我的英语也不是最好的。 – seb2704