mvn eclipse 期间 Maven checkstyle 错误:eclipse

问题描述 投票:0回答:10

目前我只是尝试下载并构建以使 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)

这是checkstyle插件在验证代码

netty-common
项目时出错。

我对这个插件不熟悉。我想知道是否可以通过从 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>

有什么想法吗?谢谢。

java maven netty
10个回答
61
投票

使用

跳过检查样式执行
-Dcheckstyle.skip

例如

mvn [YOUR_COMMAND] -Dcheckstyle.skip

26
投票

CheckStyle 是 Maven 的一个模块,用于检查代码的样式,例如制表符而不是空格。 Netty 使用它来防止基本的格式错误。

如果您计划为 Netty 做出贡献,则不应删除该插件,因为这可能意味着您的补丁将永远不会应用。

如果您只是用来玩玩,您可以随意删除该插件,因为它的唯一目的是验证安装,而不是更改安装中的内容。

如果您选择保留它,您应该查看输出日志以查看检测到的错误,以快速修复错误,请参阅 this Matthew Farwell 的回答。

    在 Package Explorer 等中右键单击 java 文件,然后选择“应用 Checkstyle 更正”。
  1. 单击问题视图中的错误,然后选择“快速修复”。这解决了这个问题。

3
投票
虽然我既不熟悉 Netty 也不熟悉 Maven Eclipse 插件,但在构建

pwm 项目时,我确实遇到了 maven-checkstyle-plugin 的问题。

这是错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check (validate) on project pwm: Failed during checkstyle configuration ....

我的解决方案(顺便说一句,这也解决了许多与maven相关的错误):

删除maven的

.m2

文件夹,然后重新构建项目。
在 Linux 系统上,.m2 文件夹通常位于您的主文件夹中 
/home/<username>/.m2

    


2
投票
如果您刚刚克隆了存储库并且构建失败,我相信您使用的是 Windows 并且 Git 配置有问题。请将“core.autocrlf”选项设置为“true”,重新克隆存储库,然后重试。

git config --global core.autocrlf true
    

2
投票
我遇到了同样的问题,我通过在我的 pom 文件中添加以下内容来禁用 pom 中的 checkstyle,它对我有用。

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <executions> <execution> <id>checkstyle-validation</id> <phase>none</phase> </execution> </executions> </plugin>
    

1
投票
在我的例子中,我只是尝试执行相同的目标,但使用 -X 选项(启用调试级别)并发现类检查样式插件正在抱怨什么。更正样式并再次运行maven -> 构建成功。


1
投票
解决此问题的最佳方法是使用 -X 选项运行 mvn install ,它将为您提供有关课堂风格问题的详细信息。您可以相应地修复课程。


1
投票
在 Linux 操作系统上,我使用

dos2unix 解决了。

cd presto; find . -type f -exec dos2unix {} \;
    

1
投票
只需执行“mvn Spotless:apply”,对我有用


0
投票
我通过删除 pom.xml 中的 check-style 配置并重建 maven 解决了这个问题。当我后来重新插入并构建时,它工作正常,没有错误。

© www.soinside.com 2019 - 2024. All rights reserved.