我编写了以下pom.xml文件,该文件应该创建一个checkstyle报告/趋势图,并在有一些checkstyle警告时中止构建过程。
<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>
问题是,如果我使用jenkins和maven目标clean install
构建maven项目,项目将被构建,但checkstyle插件不会被执行。所以我使用了clean install site
。使用site
已创建报告和趋势图,但构建过程仍然无法停止。在那之后我使用clean install site checkstyle:check -Dcheckstyle.config.location="https://dustplanet.de/checkstyle.xml"
,这样我的构建过程失败了,但是分析结果以及tend图表没有显示任何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 git@essgitlab.fzi.de:SysKit/SYSKIT.git # timeout=10
Fetching upstream changes from git@essgitlab.fzi.de:SysKit/SYSKIT.git
> git --version # timeout=10
using GIT_SSH to set credentials
> git fetch --tags --progress git@essgitlab.fzi.de: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 rebmann@fzi.de
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 rebmann@fzi.de
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插件才能正常工作。我该如何解决这个警告?
编辑2
好吧问题是我忘记了&#34; s&#34;插入<groupId>org.apache.maven.plugin</groupId>
之后。插件仍然没有被执行,但我现在将构建标记为jenkins中的checkstyle插件不稳定或失败。我本应该这样做的第一种方式是帮助。
答案 0 :(得分: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