idea编译项目时,出现如下报错:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0:check (validate) on project devops-brain: Failed during checkstyle configuration: Cannot set property 'cacheFile' to 'F:\Copote\Code\devops-brain\devops-brain\target/checkstyle-cachefile': InvocationTargetException: com/google/common/io/Flushables: com.google.common.io.Flushables -> [Help 1]

Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin_maven

 进入pom.xml所在目录,如图:

Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin_apache_02

执行如下命令,查看详细日志:

mvn clean package -e -X
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0:check (validate) on project devops-brain: Failed during checkstyle configuration: Cannot set property 'cacheFile' to 'target/c
achefile': InvocationTargetException: com/google/common/io/Flushables: com.google.common.io.Flushables -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0:check (validate) on project devops-brain: Failed during checkstyle configurati
on
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
...
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Failed during checkstyle configuration
at org.apache.maven.plugins.checkstyle.CheckstyleViolationCheckMojo.execute (CheckstyleViolationCheckMojo.java:534)
...
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Cannot set property 'cacheFile' to 'target/cachefile'
at com.puppycrawl.tools.checkstyle.api.AutomaticBean.tryCopyProperty (AutomaticBean.java:237)
at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure (AutomaticBean.java:191)
...
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
...
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: java.lang.NoClassDefFoundError: com/google/common/io/Flushables
at com.puppycrawl.tools.checkstyle.PropertyCacheFile.flushAndCloseOutStream (PropertyCacheFile.java:167)
...
Caused by: java.lang.ClassNotFoundException: com.google.common.io.Flushables
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass (SelfFirstStrategy.java:50)
...
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
[ERROR]
[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/MojoExecutionException

定位到日志:

Caused by: java.lang.ClassNotFoundException: com.google.common.io.Flushables

这个类在如下依赖jar包中,在pom中添加如下依赖:

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>

如果依赖引入后还不行,请删除本地maven库中guava目录,重新导入: 

Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin_maven_03

重新编译项目,如果没其他错误,即可成功。不幸的是,作者编译后继续报错如下:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0:check (validate) on project devops-brain-manager-bean: Failed during checkstyle execution: There are 8 errors reported by Checkstyle 8.18 with ../../code-style/checkstyle.xml ruleset. -> [Help 1]
 

继续执行如下命令,查看详细日志:

mvn clean package -e -X

如图:

[INFO] 寮?濮嬫鏌モ?︹??
[ERROR] F:\Copote\Code\...\dto\AlertRuleDto.java:7:4: 鏈煡鏍囩 'description' 銆? [JavadocType
]
[ERROR] F:\Copote\Code\...\entity\AlertRuleEntity.java:7:4: 鏈煡鏍囩 'description' 銆? [Javad
ocType]
[ERROR] F:\Copote\Code\...\entity\AlertsEntity.java:7:4: 鏈煡鏍囩 'description' 銆? [JavadocT
ype]
[ERROR] F:\Copote\Code\...\entity\BaseEntity.java:12:47: WhitespaceAround: '{' is not preceded wi
th whitespace. [WhitespaceAround]
[ERROR] F:\Copote\Code\...\entity\HostConfigEntity.java:11:49: WhitespaceAround: '{' is not prece
ded with whitespace. [WhitespaceAround]
[ERROR] F:\Copote\Code\...\entity\HostEntity.java:7:4: 鏈煡鏍囩 'Author' 銆? [JavadocType]
[ERROR] F:\Copote\Code\...\entity\HostEntity.java:8:4: 鏈煡鏍囩 'Date' 銆? [JavadocType]
[ERROR] F:\Copote\Code\...\entity\HostEntity.java:9:4: 鏈煡鏍囩 'Version' 銆? [JavadocType]
[ERROR] F:\Copote\Code\...\entity\HostEntity.java:10:4: 鏈煡鏍囩 'Description' 銆? [JavadocTy
pe]
[ERROR] F:\Copote\Code\...\entity\HostTagEntity.java:6: 缂哄皯 Javadoc 銆? [JavadocType]
[ERROR] F:\Copote\Code\...\entity\MetricEntity.java:8:4: 鏈煡鏍囩 'description' 銆? [JavadocT
ype]
[ERROR] F:\Copote\Code\...\entity\MetricTemplateEntity.java:7:4: 鏈煡鏍囩 'description' 銆? [
JavadocType]
妫?鏌ュ畬鎴愩??
[INFO] ------------------------------------------------------------------------
...
Caused by: org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorException: There are 12 errors reported by Checkstyle 8.18 with ../../code-style/checkstyle.xml ruleset.
at org.apache.maven.plugins.checkstyle.exec.DefaultCheckstyleExecutor.executeCheckstyle (DefaultCheckstyleExecutor.java:309)

定位到日志:

There are 8 errors reported by Checkstyle 8.18 with ../../code-style/checkstyle.xml ruleset. -> [Help 1]

原因是存在多处代码不符合风格。逐个检查修改即可。