我在Windows系统上有一些关于构建项目的问题。我的项目使用formatter-maven-plugin,目标是"validate“。在GitHub中推送项目之前,我先对其进行格式化并推送。之后,我将其克隆到我的windows计算机上,并尝试"mvn全新安装“,但我得到:
 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>发布于 2020-03-04 01:09:59
发布于 2019-06-19 22:33:34
我认为您在格式化时遗漏了一个文件。根据有关该主题的this issue,似乎记录了一条更好的错误消息,表明存在问题的文件。如果您将Maven格式化程序升级到最新的稳定版本,您应该会看到一条新的错误消息,格式如下:
文件'fileName‘以前没有格式化过。请格式化文件并提交后再运行验证!
发布于 2021-02-05 16:48:36
有两种方法可以解决这个问题:
你可以使用.gitattributes设置text eol = lf,保持git fench代码文件以LF结尾。
另一种是使用formatter-maven-plugin标签lineEnding,设置<lineEnding>KEEP</lineEnding>,让行分隔符依赖于文件本身,而不是系统。
我更喜欢第二种方式,因为格式应该保持系统独立性。
https://stackoverflow.com/questions/56670074
复制相似问题