Fork me on GitHub

Tutorial 4

E04: Reuse a subprojection to different Maven POM elements

A Maven project has a group id, artifact id and a version. So does a Maven dependency. Now we reuse the same sub projection for unrelated, but similar parts of the document. This is possible because the structure of our projection does not need to follow the structure of the document.

Second we define a simple setter in the projection interface to show how element values can be modified.

Projection API

public interface MavenPOM {
    * When I see an artifact with id and group and version, I call it an artifact.
    * (adapted from James Whitcomb Riley)
    public interface Artifact {
        String getGroupId();
        String getArtifactId();
        String getVersion();
    String getName();
    void setName(String name);
    Artifact getProjectId();
    Artifact[] getDependencies();

Example Code

MavenPOM pom = new XBProjector(Flags.TO_STRING_RENDERS_XML).io().fromURLAnnotation(MavenPOM.class);
pom.setName("New name");
for (Artifact artifact:pom.getDependencies()) {
    if (artifact.equals(pom.getProjectId())) {
        System.out.println("Hmm... your project depends on itself!");
        throw new AssertionError();