Java – How can I solve the maven-formatter-plugin problem?

How can I solve the maven-formatter-plugin problem?… here is a solution to the problem.

How can I solve the maven-formatter-plugin problem?

I’m having some issues building projects on a Windows system. My project uses formatter-maven-plugin with a target of “validation”. Before pushing the project in GitHub, I formatted it and pushed it. After that, I clone it to my Windows computer and tried “mvn clean install”, but I get:

 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!

This problem does not exist in Linux. Why is that? I did format it before inserting it into Git. Why is there no problem on Linux? Change the goal of the format I can’t.

<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>

Solution

Based on official usage documentation:

Run the plug-in using the format target.

mvn formatter:format

After doing this once, you should be able to function normally.

Related Problems and Solutions