Pom.xml for sub-module not processed
A pom.xml file of a sub-module of a maven project does not get processed when the configuration of the maven plugin is in the parent pom and ratchetFrom is configured. Running mvn spotless:apply or spotless:check from the main pom.xml or the sub pom.xml doesn't make a difference. Also, specifying '**/pom.xml' in the includes of the 'pom' section of the configuration still only processes the main pom.xml.
Configurations in the poms:
pom.xml
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.20.0</version>
<configuration>
<ratchetFrom>origin/main</ratchetFrom>
<pom>
<sortPom>
<expandEmptyElements>false</expandEmptyElements>
<sortDependencies>scope,groupId,artifactId</sortDependencies>
</sortPom>
</pom>
</configuration>
</plugin>
sub/pom.xml
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
</plugin>
Running mvn with -X shows more files being checked, but the output only shows git file names instead of the actual checked file's names, so that output isn't useful. eg.
...
[DEBUG] file=C:\Users\JanD\.config\jgit\config, isRacyClean=false, read=2022-01-25 11:26:15.195429900, lastModified=2022-01-05 15:47:40.628742000, delta=1712314566687900 ns, racy<=2500000000 ns
[DEBUG] file=C:\Users\JanD\.config\jgit\config, is unmodified
[DEBUG] file=C:\Program Files\Git\etc\gitconfig, isRacyClean=false, read=2022-01-25 11:26:15.512368500, lastModified=2021-08-12 14:32:52.021928000, delta=14334803490440500 ns, racy<=2500000000 ns
[DEBUG] file=C:\Program Files\Git\etc\gitconfig, is unmodified
[DEBUG] file=C:\Users\JanD\.gitconfig, isRacyClean=false, read=2022-01-25 11:26:15.569986800, lastModified=2021-11-08 13:49:25.543076000, delta=6730610026910800 ns, racy<=2500000000 ns
[DEBUG] file=C:\Users\JanD\.gitconfig, is unmodified
...
Maven 3.6.3 Spotless 2.20.0 (also happens on 2.17.6) Windows 10 Reproduction repo Branch 'main' contains the setup, branch 'malformed' contains changes to make the poms badly formatted. Check the README.md there for more info.
I tried reproducing based on the provided repository. I can't reproduce the issue:
mvn spotless:apply
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] spotless test [pom]
[INFO] sub [pom]
Downloading from central: https://repo.maven.apache.org/maven2/com/diffplug/spotless/spotless-maven-plugin/2.20.0/spotless-maven-plugin-2.20.0.pom
...
Downloaded from central: https://repo.maven.apache.org/maven2/com/diffplug/spotless/spotless-lib/2.22.0/spotless-lib-2.22.0.jar (302 kB at 255 kB/s)
Feb 23, 2023 9:50:44 PM com.diffplug.spotless.glue.pom.SortPomFormatterFunc$MySortPomLogger info
INFO: Sorting file /var/folders/8b/p64c8tfs4d7gf3v8tcmwbz580000gn/T/pom12689959448582750400.xml
Feb 23, 2023 9:50:44 PM com.diffplug.spotless.glue.pom.SortPomFormatterFunc$MySortPomLogger info
INFO: Saved sorted pom file to /var/folders/8b/p64c8tfs4d7gf3v8tcmwbz580000gn/T/pom12689959448582750400.xml
Feb 23, 2023 9:50:44 PM com.diffplug.spotless.glue.pom.SortPomFormatterFunc$MySortPomLogger info
INFO: Sorting file /var/folders/8b/p64c8tfs4d7gf3v8tcmwbz580000gn/T/pom12217429336829630831.xml
Feb 23, 2023 9:50:44 PM com.diffplug.spotless.glue.pom.SortPomFormatterFunc$MySortPomLogger info
INFO: Pom file is already sorted, exiting
[INFO]
[INFO] -------------------------< jandhollander:sub >--------------------------
[INFO] Building sub 1.0 [2/2]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- spotless-maven-plugin:2.20.0:apply (default-cli) @ sub ---
Feb 23, 2023 9:50:44 PM com.diffplug.spotless.glue.pom.SortPomFormatterFunc$MySortPomLogger info
INFO: Sorting file /var/folders/8b/p64c8tfs4d7gf3v8tcmwbz580000gn/T/pom16797294105294033788.xml
Feb 23, 2023 9:50:44 PM com.diffplug.spotless.glue.pom.SortPomFormatterFunc$MySortPomLogger info
INFO: Saved sorted pom file to /var/folders/8b/p64c8tfs4d7gf3v8tcmwbz580000gn/T/pom16797294105294033788.xml
Feb 23, 2023 9:50:44 PM com.diffplug.spotless.glue.pom.SortPomFormatterFunc$MySortPomLogger info
INFO: Sorting file /var/folders/8b/p64c8tfs4d7gf3v8tcmwbz580000gn/T/pom11498531949461299209.xml
Feb 23, 2023 9:50:44 PM com.diffplug.spotless.glue.pom.SortPomFormatterFunc$MySortPomLogger info
INFO: Pom file is already sorted, exiting
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for spotless test 1.0:
[INFO]
[INFO] spotless test ...................................... SUCCESS [ 3.736 s]
[INFO] sub ................................................ SUCCESS [ 0.042 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.253 s
[INFO] Finished at: 2023-02-23T21:50:44+04:00
[INFO] ------------------------------------------------------------------------
We see both pom has been formatted successfully (1st try is a reformatting, 2nd try is spotless checking idempotency).
I would close this ticket.