Skip to content

Commit 87a3dd3

Browse files
committed
Blog about DOMTrip
1 parent d0b982d commit 87a3dd3

File tree

1 file changed

+73
-0
lines changed
  • content/en/blog/cstamas/2026/02/domtrip

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
title: "DOMTrip"
3+
date: 2026-02-05T15:07:53+01:00
4+
draft: false
5+
authors: cstamas
6+
author: cstamas ([@cstamas](https://bsky.app/profile/cstamas.bsky.social))
7+
categories:
8+
- Blog
9+
tags:
10+
- maven
11+
- pom
12+
projects:
13+
- DOMTrip
14+
---
15+
16+
{{% pageinfo %}}
17+
18+
Round-trip editing is a programmatic changing/editing of an existing XML document, like for example a Maven POM is, while
19+
preserving all the formatting, comments and all properties of the original document.
20+
21+
{{% /pageinfo %}}
22+
23+
Programmatic "editing" of POMs and other Maven related (mostly XML) files was long time requirement. Just think about
24+
Maven Release Plugin that "rewrites" the version of project during release process.
25+
26+
Moreover, as Maven 4 is coming, the good old Xpp3Dom parser was out of the question, as Maven 4 model contains
27+
substantial changes, and moreover, is not using anymore the Xpp3Dom parser, but the Woodstox XML parser instead.
28+
Still, Maven universe, and especially legacy Maven universe was not always "good citizen" when it comes to XML, many
29+
POMs have to be "lax parsed", as they had (known or unknown) issues.
30+
31+
Historically, the best choice for "round-trip editing" was [DecentXML](https://central.sonatype.com/artifact/de.pdark/decentxml/versions), a project that since died off. It was used
32+
(and AFAIK, still is) by Eclipse M2E and Tycho. We ignored this library, given it seems dead and unmaintained, last release of it happened
33+
in 2014, and there is no available canonical source repository for it either (only some unmaintained forks on GH).
34+
35+
Next, Maven itself (like the release plugin) uses JDom2. We tried to adopt it, but it was really suitable for "smaller
36+
edits", like version setting in case of release plugin. And also had issues. Curious ones can read the lengthy
37+
discussion on [Maven Release Plugin issue](https://github.com/apache/maven-release/issues/1381), why JDom2 does not work for us.
38+
39+
There are many other libraries doing similar thing to our requirements, we tried them all and we dropped them all.
40+
Some of these are:
41+
* Pom Tuner https://github.com/l2x6/pom-tuner
42+
* PME https://github.com/project-ncl/pom-manipulation-ext
43+
* Maven Model Helper https://github.com/fabric8io/maven-model-helper
44+
* (deprecated before release) Nielsen https://github.com/maveniverse/nielsen (uses JDom2, and this codebase has long history: origins are from Maven release and other plugins plugin, that were collected and forked and improved by one Maven PMC member, that were forked and improved by a German team, and was finally forked and somewhat improved by me in Maveniverse Nielsen, but it was never released it; is superseded by DOMTrip)
45+
46+
But none of these suited to us. Our goals were:
47+
* do not depend on any Maven internal nor legacy stuff (like Model or Xpp3Dom)
48+
* ideally, to not have any dependency, or just minimal ones
49+
* to 100% support lossless round-tripping and editing
50+
* to support most of Maven related files (hence, XML, with some "extras" for Maven specific stuff)
51+
52+
In fact, it was DecentXML, that was closest to our expectations, but that project was abandoned. Hence, we came up with DOMTrip:
53+
* Sources https://github.com/maveniverse/domtrip
54+
* Site https://maveniverse.github.io/domtrip/
55+
56+
DOMTrip is a Java 17 library that:
57+
* has no dependencies
58+
* does full and lossless round-trip editing
59+
* supports general XML, with extra support for Maven files like POM, Settings, Toolchains and Extensions XML files
60+
* offers "low level" and "high level" operations
61+
62+
DOMTrip is being used you run `mvn toolbox:versions -Dapply` (to apply version upgrades to POM) for example. It will
63+
"edit" your POM, but you still need to review and eventually commit the changes.
64+
65+
Just to give some perspective about "high level" operations, let me give you an example: assume you know that POM
66+
contains a plugin GA with version V1. And you want to upgrade that plugin to version V2. To achieve this, one pay
67+
use `boolean updatePlugin(boolean upsert, Coordinates coordinates)` method of `POMEditor`. This method will perform
68+
following steps for you (while keeping all the formatting and comments of POM): It will look for GA plugin in
69+
`project/build/plugins`, and if found, and version present, and is not a property, will update it, and work is done.
70+
But, if version is a property, DOMTrip will go and update the property. Finally, if version is not even present,
71+
will go to `project/build/pluginManagement/plugins` and rinse, repeat. Is smart.
72+
73+
Have fun with it!

0 commit comments

Comments
 (0)