how to make tidy-maven-plugin and spotless-maven-plugin to ignore comments formatting in pom.xml or do it in the same way?

288 Views Asked by At

I am trying out maven plugins for maven pom.xml validation,
as our project pom.xml was in much neglected state, w/o formating etc.

I found that spotless can do with config later below by

mvn spotless:apply

and https://www.mojohaus.org/tidy-maven-plugin/

mvn tidy:pom.

The problem: while both are good and pointed to some problem, and agree about meaningful pom.xml content,
they disagree about how to write comments (something, that I don't really want to make strict)

spotless wants multiline comment block to start like

<plugin>   
<!--

and tidy wants in 1 line

<plugin><!--

Question: how to make these plugins to ignore comments formatting or do it in the same way?

      <!-- mvn spotless:check by default is mapped to mvn verify (verify lifecycle phase)-->
      <plugin>
        <groupId>com.diffplug.spotless</groupId>
        <artifactId>spotless-maven-plugin</artifactId>
        <version>2.30.0</version>
        <configuration>
          <java>
            <googleJavaFormat></googleJavaFormat>
          </java>
          <pom>
            <sortPom>
              <!-- see https://github.com/diffplug/spotless/blob/main/plugin-maven/README.md#sortpom -->
            </sortPom>
          </pom>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>check</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
1

There are 1 best solutions below

0
user2381162 On

Spotless is using sortpom-maven-plugin to sort pom files. Sortpom parses the whole file as xml content and regenerates the file from that xml structure. Most information about line numbers and individual formatting is lost in this process, including formatted comments. I.e it treats the comments as any other xml content. There are ways to ignore sections in the pom file with Sortpom, see SORTPOM IGNORE, but I don't know if it applicable to your use case.