formatter-maven-plugin: XML formatting is not thread safe (parallel build support)

Describe the bug Trying to run the formatter to fix XML files (including the pom.xml files) on a large project (200 modules). Given the size, a parallel build is mandatory to contain the build times, and leverage modern multi-core CPUs. Testing the plugin, I had occasional failures, e.g.:

[ERROR] Failed to execute goal net.revelc.code.formatter:formatter-maven-plugin:2.14.0:format (default-cli) on project gs-web-oseo: Execution default-cli of goal net.revelc.code.formatter:formatter-maven-plugin:2.14.0:format failed: String index out of range: -2

Weird enough, I cannot find any stack trace. The end result is ruined XML files as well (thankfully they can be easily recovered via version control).

It turns out, even runs wtihout errors ruins the checkout, here is maven trying to build the files:

INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-readable POM /home/aaime/devel/git-gs-clean/src/security/pom.xml: ISO-889 @ 
[FATAL] Non-readable POM /home/aaime/devel/git-gs-clean/src/wcs/pom.xml: ISO-889 @ 
[FATAL] Non-parseable POM /home/aaime/devel/git-gs-clean/src/wcs2_0/pom.xml: Unrecognised tag: 'groupImodelVersion' (position: START_TAG seen ...</parent>\n\n\t<groupImodelVersion>... @17:22)  @ line 17, column 22
[FATAL] Non-parseable POM /home/aaime/devel/git-gs-clean/src/wms/pom.xml: end tag name </a> must match start tag name <artifactId> from line 172 (position: TEXT seen ...<artifactId>hamcrest-library</a\r... @172:36)  @ line 172, column 36
[FATAL] Non-parseable POM /home/aaime/devel/git-gs-clean/src/kml/pom.xml: unexpected character in markup 4 (position: START_TAG seen ...apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">\n<4... @7:3)  @ line 7, column 3
[FATAL] Non-parseable POM /home/aaime/devel/git-gs-clean/src/rest/pom.xml: Unrecognised tag: 'groupId' (position: START_TAG seen ...<!-- Test dependencies -->\n\t\t\n\t\t\t<groupId>... @31:13)  @ line 31, column 13
[FATAL] Non-parseable POM /home/aaime/devel/git-gs-clean/src/restconfig/pom.xml: expected START_TAG or END_TAG not TEXT (position: TEXT seen ...</artifactId>\nversion>${project.version}</... @46:29)  @ line 46, column 29
[FATAL] Non-parseable POM /home/aaime/devel/git-gs-clean/src/web/app/pom.xml: markup not allowed inside attribute value - illegal <  (position: TEXT seen ...<beans xmlns="http://www.springframework.orupId>\n          <... @477:12)  @ line 477, column 12
[FATAL] Non-parseable POM /home/aaime/devel/git-gs-clean/src/web/wms/pom.xml: markup not allowed inside attribute value - illegal <  (position: TEXT seen ...eflector" class="org.geoserver.kml.WebMapServicegroupId>    \n    <... @14:6)  @ line 14, column 6
[FATAL] Non-parseable POM /home/aaime/devel/git-gs-clean/src/web/wfs/pom.xml: expected = after attribute name (position: START_DOCUMENT seen ...id="rdeCoveraeorePanel" classroserver.web.data.resce.DatStrePaneo"... @7:74)  @ line 7, column 74
[FATAL] Non-parseable POM /home/aaime/devel/git-gs-clean/src/web/gwc/pom.xml: end tag name </roupId> must match start tag name <scope> from line 69 (position: TEXT seen ...<scope>test</roupId>... @69:24)  @ line 69, column 24
[FATAL] Non-parseable POM /home/aaime/devel/git-gs-clean/src/web/security/core/pom.xml: markup not allowed inside attribute value - illegal <  (position: TEXT seen ...<project xmlns="http://maven.apache.orgaent>\n\t\t<... @13:4)  @ line 13, column 4
[FATAL] Non-parseable POM /home/aaime/devel/git-gs-clean/src/web/security/jdbc/pom.xml: unexpected character in markup \n (position: START_TAG seen ...<parent>\n\t\t<groupId>org.geoserver.web<\n... @14:1)  @ line 14, column 1
[FATAL] Non-parseable POM /home/aaime/devel/git-gs-clean/src/web/security/ldap/pom.xml: expected START_TAG or END_TAG not TEXT (position: TEXT seen ...<groupId>org.geoservemr.web</groupId>\nartifactId>gs-web-sec-core</... @26:29)  @ line 26, column 29
[FATAL] Non-parseable POM /home/aaime/devel/git-gs-clean/src/community/pom.xml: expected > to end empty tag not x (position: TEXT seen ...</descriptor>\n\t\t\t\t\t\t<bees/x... @74:14)  @ line 74, column 14
[FATAL] Non-parseable POM /home/aaime/devel/git-gs-clean/src/extension/pom.xml: in comment after two dashes (--) next character must be > not p (position: START_DOCUMENT seen <?xml version="1.0" encoding="ISO-8859-1"?>\n<!-- \n Copyr<--p... @3:11)  @ line 3, column 11
 @ 
[ERROR] The build could not read 16 projects -> [Help 1]
[ERROR]   
[ERROR]   The project  (/home/aaime/devel/git-gs-clean/src/security/pom.xml) has 1 error
[ERROR]     Non-readable POM /home/aaime/devel/git-gs-clean/src/security/pom.xml: ISO-889
[ERROR]   
[ERROR]   The project  (/home/aaime/devel/git-gs-clean/src/wcs/pom.xml) has 1 error
[ERROR]     Non-readable POM /home/aaime/devel/git-gs-clean/src/wcs/pom.xml: ISO-889
[ERROR]   
[ERROR]   The project  (/home/aaime/devel/git-gs-clean/src/wcs2_0/pom.xml) has 1 error
[ERROR]     Non-parseable POM /home/aaime/devel/git-gs-clean/src/wcs2_0/pom.xml: Unrecognised tag: 'groupImodelVersion' (position: START_TAG seen ...</parent>\n\n\t<groupImodelVersion>... @17:22)  @ line 17, column 22 -> [Help 2]
[ERROR]   
[ERROR]   The project  (/home/aaime/devel/git-gs-clean/src/wms/pom.xml) has 1 error
[ERROR]     Non-parseable POM /home/aaime/devel/git-gs-clean/src/wms/pom.xml: end tag name </a> must match start tag name <artifactId> from line 172 (position: TEXT seen ...<artifactId>hamcrest-library</a\r... @172:36)  @ line 172, column 36 -> [Help 2]
[ERROR]   
[ERROR]   The project  (/home/aaime/devel/git-gs-clean/src/kml/pom.xml) has 1 error
[ERROR]     Non-parseable POM /home/aaime/devel/git-gs-clean/src/kml/pom.xml: unexpected character in markup 4 (position: START_TAG seen ...apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">\n<4... @7:3)  @ line 7, column 3 -> [Help 2]
[ERROR]   
[ERROR]   The project  (/home/aaime/devel/git-gs-clean/src/rest/pom.xml) has 1 error
[ERROR]     Non-parseable POM /home/aaime/devel/git-gs-clean/src/rest/pom.xml: Unrecognised tag: 'groupId' (position: START_TAG seen ...<!-- Test dependencies -->\n\t\t\n\t\t\t<groupId>... @31:13)  @ line 31, column 13 -> [Help 2]
[ERROR]   
[ERROR]   The project  (/home/aaime/devel/git-gs-clean/src/restconfig/pom.xml) has 1 error
[ERROR]     Non-parseable POM /home/aaime/devel/git-gs-clean/src/restconfig/pom.xml: expected START_TAG or END_TAG not TEXT (position: TEXT seen ...</artifactId>\nversion>${project.version}</... @46:29)  @ line 46, column 29 -> [Help 2]
[ERROR]   
[ERROR]   The project  (/home/aaime/devel/git-gs-clean/src/web/app/pom.xml) has 1 error
[ERROR]     Non-parseable POM /home/aaime/devel/git-gs-clean/src/web/app/pom.xml: markup not allowed inside attribute value - illegal <  (position: TEXT seen ...<beans xmlns="http://www.springframework.orupId>\n          <... @477:12)  @ line 477, column 12 -> [Help 2]
[ERROR]   
[ERROR]   The project  (/home/aaime/devel/git-gs-clean/src/web/wms/pom.xml) has 1 error
[ERROR]     Non-parseable POM /home/aaime/devel/git-gs-clean/src/web/wms/pom.xml: markup not allowed inside attribute value - illegal <  (position: TEXT seen ...eflector" class="org.geoserver.kml.WebMapServicegroupId>    \n    <... @14:6)  @ line 14, column 6 -> [Help 2]
[ERROR]   
[ERROR]   The project  (/home/aaime/devel/git-gs-clean/src/web/wfs/pom.xml) has 1 error
[ERROR]     Non-parseable POM /home/aaime/devel/git-gs-clean/src/web/wfs/pom.xml: expected = after attribute name (position: START_DOCUMENT seen ...id="rdeCoveraeorePanel" classroserver.web.data.resce.DatStrePaneo"... @7:74)  @ line 7, column 74 -> [Help 2]
[ERROR]   
[ERROR]   The project  (/home/aaime/devel/git-gs-clean/src/web/gwc/pom.xml) has 1 error
[ERROR]     Non-parseable POM /home/aaime/devel/git-gs-clean/src/web/gwc/pom.xml: end tag name </roupId> must match start tag name <scope> from line 69 (position: TEXT seen ...<scope>test</roupId>... @69:24)  @ line 69, column 24 -> [Help 2]
[ERROR]   
[ERROR]   The project  (/home/aaime/devel/git-gs-clean/src/web/security/core/pom.xml) has 1 error
[ERROR]     Non-parseable POM /home/aaime/devel/git-gs-clean/src/web/security/core/pom.xml: markup not allowed inside attribute value - illegal <  (position: TEXT seen ...<project xmlns="http://maven.apache.orgaent>\n\t\t<... @13:4)  @ line 13, column 4 -> [Help 2]
[ERROR]   
[ERROR]   The project  (/home/aaime/devel/git-gs-clean/src/web/security/jdbc/pom.xml) has 1 error
[ERROR]     Non-parseable POM /home/aaime/devel/git-gs-clean/src/web/security/jdbc/pom.xml: unexpected character in markup \n (position: START_TAG seen ...<parent>\n\t\t<groupId>org.geoserver.web<\n... @14:1)  @ line 14, column 1 -> [Help 2]
[ERROR]   
[ERROR]   The project  (/home/aaime/devel/git-gs-clean/src/web/security/ldap/pom.xml) has 1 error
[ERROR]     Non-parseable POM /home/aaime/devel/git-gs-clean/src/web/security/ldap/pom.xml: expected START_TAG or END_TAG not TEXT (position: TEXT seen ...<groupId>org.geoservemr.web</groupId>\nartifactId>gs-web-sec-core</... @26:29)  @ line 26, column 29 -> [Help 2]
[ERROR]   
[ERROR]   The project  (/home/aaime/devel/git-gs-clean/src/community/pom.xml) has 1 error
[ERROR]     Non-parseable POM /home/aaime/devel/git-gs-clean/src/community/pom.xml: expected > to end empty tag not x (position: TEXT seen ...</descriptor>\n\t\t\t\t\t\t<bees/x... @74:14)  @ line 74, column 14 -> [Help 2]
[ERROR]   
[ERROR]   The project  (/home/aaime/devel/git-gs-clean/src/extension/pom.xml) has 1 error
[ERROR]     Non-parseable POM /home/aaime/devel/git-gs-clean/src/extension/pom.xml: in comment after two dashes (--) next character must be > not p (position: START_DOCUMENT seen <?xml version="1.0" encoding="ISO-8859-1"?>\n<!-- \n Copyr<--p... @3:11)  @ line 3, column 11 -> [Help 2]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/ModelParseException

Versions (OS, Maven, Java, and others, as appropriate):

  • Affected version(s) of this project: 2.14.0
  • OS: Linux Mint
  • Others:

To Reproduce Steps to reproduce the behavior (or a link to an example repository that reproduces the problem):

  1. Checkout this branch: https://github.com/aaime/geoserver/tree/eclipse_xml_formatter
  2. Back out the formatting changes, keeping only the formatter setup: git reset --hard HEAD^
  3. cd src
  4. Run the formatter on all projects, with a parallel build: mvn formatter:format -T4 -Prelease,communityRelease
  5. Watch the fireworks start

Expected behavior All of the xml files should be properly formatted.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 29 (16 by maintainers)

Most upvoted comments

@aaime It doesn’t matter if it’s package or validate or another goal in the maven lifecycle. The main point is that there’s often a difference in behavior between running a plugin as part of a build lifecycle (mvn <lifecyclegoal> otherplugin:goal) vs. as standalone (mvn otherplugin:goal).

~I’m having trouble reproducing this either way. Can you create a sample repository that reproduces the problem? Or point me to a public one where it occurs?~ (EDIT: sorry, I overlooked the example you provided)

Also, I noticed you’re using this plugin for formatting pom.xml files. Please note that this plugin is not as good as other plugins that are more well-suited for pom.xml files. Specifically, I recommend using the sortpom-maven-plugin, which not only does the XML formatting, it also standardizes the POM sections, sorts and groups dependencies by scope and groupId, etc. It’s much better than this plugin, which has only basic XML formatting.