首页 > 解决方案 > 如何解决 maven-formatter-plugin 的问题?

问题描述

我在 Windows 系统上构建项目时遇到了一些问题。我的项目使用带有“验证”目标的 formatter-maven-plugin。在 GitHub 中推送项目之前,我将其格式化并推送。之后,我将它克隆到我的 Windows 计算机上并尝试“mvn clean install”,但我得到:

 Failed to execute goal net.revelc.code.formatter:formatter-maven-plugin:2.9.0:validate (default) on project application: File 'C:\Users\AUser\Desktop\demo\application\src\main\java\com\myapp\Application.java' has not been previously formatted. Please format file and commit before running validation!

在 Linux 中不存在这个问题。这是为什么?在推送 Git 之前,我确实对其进行了格式化。为什么linux上不存在问题?改变格式的目标我不能。

<plugin>
                <groupId>net.revelc.code.formatter</groupId>
                <artifactId>formatter-maven-plugin</artifactId>
                <version>2.9.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>validate</goal>
                        </goals>
                        <configuration>
                            <configFile>${project.basedir}/../eclipse/eclipse-formatter.xml</configFile>
                            <encoding>UTF-8</encoding>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

标签: javaspringmavenformatter

解决方案


根据官方使用文档

使用格式目标运行插件。

mvn formatter:format

这样做一次后,您应该可以正常运行了。


推荐阅读