Java 如何修复 maven 检查样式错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35149422/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to fix the maven check style error
提问by Joe.wang
Currently I just tried to download and build to make the Netty source code work. But when I tried to run the command mvn eclipse:eclipse
in the source folder. I got an error said
目前我只是尝试下载和构建以使 Netty 源代码工作。但是当我尝试mvn eclipse:eclipse
在源文件夹中运行命令时。我有一个错误说
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.10:check (check-style) on project netty-common: Failed during checkstyle execu
tion: There are 304 checkstyle errors. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.10:check (check-style) on proj
ect netty-common: Failed during checkstyle execution
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.MojoExecutor.executeForkedExecutions(MojoExecutor.java:352)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:197)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Failed during checkstyle execution
at org.apache.maven.plugin.checkstyle.CheckstyleViolationCheckMojo.execute(CheckstyleViolationCheckMojo.java:374)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 24 more
Caused by: org.apache.maven.plugin.checkstyle.CheckstyleExecutorException: There are 304 checkstyle errors.
at org.apache.maven.plugin.checkstyle.DefaultCheckstyleExecutor.executeCheckstyle(DefaultCheckstyleExecutor.java:218)
at org.apache.maven.plugin.checkstyle.CheckstyleViolationCheckMojo.execute(CheckstyleViolationCheckMojo.java:365)
It is error of the checkstyle plugin when validating the code netty-common
project.
验证代码netty-common
项目时是checkstyle插件的错误。
I am not familiar with this plugin . I want to know if I can just ignore it by removing the configuration from the pom.xml(in the ). like below.
我对这个插件不熟悉。我想知道我是否可以通过从 pom.xml(在 )中删除配置来忽略它。像下面。
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>check-style</id>
<goals>
<goal>check</goal>
</goals>
<phase>validate</phase>
<configuration>
<consoleOutput>true</consoleOutput>
<logViolationsToConsole>true</logViolationsToConsole>
<failsOnError>true</failsOnError>
<failOnViolation>true</failOnViolation>
<configLocation>io/netty/checkstyle.xml</configLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-build</artifactId>
<version>21</version>
</dependency>
</dependencies>
</plugin>
Any idea ? Thanks.
任何的想法 ?谢谢。
采纳答案by Ferrybig
CheckStyle is a module of maven that check the style of the code for things like tabs instead of spaces. Netty is using this to prevent basic formatting mistakes.
CheckStyle 是 maven 的一个模块,用于检查诸如制表符而不是空格之类的代码样式。Netty 正在使用它来防止基本的格式错误。
If you are planning to contribute to Netty, you should NOT remove the plugin as it probably means your patch will never applied.
如果您打算为 Netty 做出贡献,则不应删除该插件,因为这可能意味着您的补丁将永远不会应用。
If you are just using to play with, you are free to remove that plugin as its only purpose is to verify the installation, and not to change things from the installation.
如果您只是用来玩,您可以随意删除该插件,因为它的唯一目的是验证安装,而不是更改安装中的内容。
If you choose to keep it, you should look in the output log to see what the mistakes are it detected, to quickly fix the mistakes, see thisanswer by Matthew Farwell.
如果您选择保留它,您应该查看输出日志以查看检测到的错误,以快速修复错误,请参阅Matthew Farwell 的这个答案。
- Right click on the java file in Package Explorer or whatever, and select 'Apply Checkstyle Corrections'.
- Click on the error in the problems view, and select 'Quick fix'. This corrects the problem.
- 在包资源管理器或其他任何地方右键单击 java 文件,然后选择“应用 Checkstyle 更正”。
- 单击问题视图中的错误,然后选择“快速修复”。这可以纠正问题。
回答by Thilina Rubasingha
Skip the check style execution using
使用跳过检查样式执行
-Dcheckstyle.skip
Ex
前任
mvn [YOUR_COMMAND] -Dcheckstyle.skip
回答by trustin
If you've just cloned the repository and the build failed, I believe you are using Windows and you have a problem with your Git configuration. Please set the 'core.autocrlf' option to 'true', re-clone the repository, and try again.
如果您刚刚克隆了存储库并且构建失败,我相信您使用的是 Windows 并且您的 Git 配置有问题。请将“core.autocrlf”选项设置为“true”,重新克隆存储库,然后重试。
git config --global core.autocrlf true
回答by Richie254
Whereas I am neither familiar with Netty nor the maven eclipse plugin, I did face an issue with the maven-checkstyle-plugin while building the pwmproject.
虽然我既不熟悉 Netty 也不熟悉 maven eclipse 插件,但我在构建pwm项目时确实遇到了 maven-checkstyle-plugin 的问题。
This was the error:
这是错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check (validate) on project pwm: Failed during checkstyle configuration ....
My Solution(which also solves many maven related errors btw):
我的解决方案(顺便说一句,它还解决了许多与 maven 相关的错误):
Delete the maven's .m2
folder, then build the project again.
On linux systems, the .m2 folder is usually in your home folder /home/<username>/.m2
删除maven的.m2
文件夹,然后重新构建项目。在 linux 系统上,.m2 文件夹通常位于您的主文件夹中/home/<username>/.m2
回答by Denys
In my case I just tried to execute same goal but with -X option (enabling debug level) and found what class check style plugin is complaining about. Corrected style and run maven again -> Build success.
就我而言,我只是尝试执行相同的目标,但使用 -X 选项(启用调试级别)并发现类检查样式插件抱怨的是什么。更正样式并再次运行 maven -> 构建成功。
回答by Ankur Shrivastava
Best approach to fix this issues by running the mvn install with -X option it will give you detail about the style issues in class. You can fix the class accordingly.
通过使用 -X 选项运行 mvn install 来解决此问题的最佳方法它将为您提供有关课堂风格问题的详细信息。您可以相应地修复类。
回答by Okpo
I solved this problem by removing the check-style configuration in my pom.xml and rebuilding maven. When I later re-inserted and build, it worked without error.
我通过删除 pom.xml 中的 check-style 配置并重建 maven 解决了这个问题。当我后来重新插入和构建时,它没有错误地工作。