A library for analyzing and programmatic editing of Maven pom.xml
files.
Its two main parts are PomTransformer
and MavenSourceTree
Transform a single pom.xml
file by using any of the pre-cooked Transformation
s or by writing your own.
A basic usage example:
import org.l2x6.pom.tuner.model.Gavtcs;
import org.l2x6.pom.tuner.PomTransformer;
import org.l2x6.pom.tuner.PomTransformer.SimpleElementWhitespace;
import org.l2x6.pom.tuner.PomTransformer.Transformation;
new PomTransformer(Paths.get("pom.xml"), StandardCharsets.UTF_8, SimpleElementWhitespace.AUTODETECT_PREFER_EMPTY)
.transform(
Transformation.addModuleIfNeeded("my-new-module", String::compareTo),
Transformation.addOrSetProperty("my-prop", "new-value"),
Transformation.addDependencyIfNeeded(new Gavtcs("org.acme", "a1", "1.2.3"),
Gavtcs.scopeAndTypeFirstComparator())
);
Characteristics:
-
Parses the given
pom.xml
file once into a DOM, applies one or moreTransformation
s and writes the file back to the disk. -
Generally keeps all formatting and whitespace, including end of line (EOL) characters (unlike many DOM writers which use the current platform’s default EOLs).
-
Indentation for newly added elements is auto-detected based on the first indent available in the file.
-
Respects the canonical ordering when adding new elements under
<project>
.
A representation of a Maven module hierarchy.
It comes in handy in a variety of scenarios:
-
Analyze relationships in the dependency graph:
-
On which other modules (including transitives) depends some given module? - see
MavenSourceTree.collect[Own|Transitive]Dependencies()
-
Which modules in the tree are required for building some given module? - see
MavenSourceTree.findRequiredModules()
-
-
Transform the
pom.xml
files:-
Set versions of the modules - see
MavenSourceTree.setVersions()
-
Reduce the tree by removing some modules from the
pom.xml
file - seeMavenSourceTree.unlinkModules()
-
<dependency>
<groupId>org.l2x6.pom-tuner</groupId>
<artifactId>pom-tuner</artifactId>
<version><!-- see below --></version>
</dependency>
Check the latest version on Maven Central: https://repo1.maven.org/maven2/org/l2x6/pom-tuner/pom-tuner/