0

I'm using the org.jvnet.jaxb2.maven2:maven-jaxb2-plugin in version 0.12.3, and I have the following problem.

  1. I generate a java files from an xsd files.

  2. I commit and push it on our git repository.

  3. I launch the same generation again (we use removeOldOutput option).

  4. For some file, git is detecting some changes, because the order of some annotations is not the same between 2 generations.

A part of the first generation:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Software", propOrder = {
    "rest"
})
public abstract class Software
    extends SoftwareResource
    implements Serializable
{

    private final static long serialVersionUID = 1L;
    @XmlElementRefs({
        @XmlElementRef(name = "resource", type = JAXBElement.class),
        @XmlElementRef(name = "software", type = JAXBElement.class),
        @XmlElementRef(name = "swapSpaceUsedCurrent", type = JAXBElement.class),
        @XmlElementRef(name = "isUTCTime", type = JAXBElement.class),
        @XmlElementRef(name = "lastStartTime", type = JAXBElement.class),
        @XmlElementRef(name = "serialNumber", type = JAXBElement.class),
        @XmlElementRef(name = "numberProcessesActiveCurrent", type = JAXBElement.class),
        @XmlElementRef(name = "pagingFileSizeCurrent", type = JAXBElement.class),
        @XmlElementRef(name = "processMemorySizeCurrent", type = JAXBElement.class),
        @XmlElementRef(name = "numUsersCurrent", type = JAXBElement.class)
    })
    protected List<JAXBElement<? extends Serializable>> rest;

    /**
     * Objects of the following type(s) are allowed in the list
     * {@link JAXBElement }{@code <}{@link Resource }{@code >}
     * {@link JAXBElement }{@code <}{@link BigInteger }{@code >}
     * {@link JAXBElement }{@code <}{@link Software }{@code >}
     * {@link JAXBElement }{@code <}{@link Boolean }{@code >}
     * {@link JAXBElement }{@code <}{@link String }{@code >}
     * {@link JAXBElement }{@code <}{@link BigInteger }{@code >}
     * {@link JAXBElement }{@code <}{@link String }{@code >}
     * {@link JAXBElement }{@code <}{@link Quantity }{@code >}
     * {@link JAXBElement }{@code <}{@link BigInteger }{@code >}
     * {@link JAXBElement }{@code <}{@link Quantity }{@code >}
     * 
     * 
     */
    public List<JAXBElement<? extends Serializable>> getRest() {
        if (rest == null) {
            rest = new ArrayList<JAXBElement<? extends Serializable>>();
        }
        return this.rest;
    }

}

The same part of the second generation:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Software", propOrder = {
    "rest"
})
public abstract class Software
    extends SoftwareResource
    implements Serializable
{

    private final static long serialVersionUID = 1L;
    @XmlElementRefs({
        @XmlElementRef(name = "numUsersCurrent", type = JAXBElement.class),
        @XmlElementRef(name = "serialNumber", type = JAXBElement.class),
        @XmlElementRef(name = "processMemorySizeCurrent", type = JAXBElement.class),
        @XmlElementRef(name = "swapSpaceUsedCurrent", type = JAXBElement.class),
        @XmlElementRef(name = "pagingFileSizeCurrent", type = JAXBElement.class),
        @XmlElementRef(name = "lastStartTime", type = JAXBElement.class),
        @XmlElementRef(name = "numberProcessesActiveCurrent", type = JAXBElement.class),
        @XmlElementRef(name = "resource", type = JAXBElement.class),
        @XmlElementRef(name = "isUTCTime", type = JAXBElement.class),
        @XmlElementRef(name = "software", type = JAXBElement.class)
    })
    protected List<JAXBElement<? extends Serializable>> rest;

    /**
     * Objects of the following type(s) are allowed in the list
     * {@link JAXBElement }{@code <}{@link BigInteger }{@code >}
     * {@link JAXBElement }{@code <}{@link String }{@code >}
     * {@link JAXBElement }{@code <}{@link Quantity }{@code >}
     * {@link JAXBElement }{@code <}{@link String }{@code >}
     * {@link JAXBElement }{@code <}{@link Quantity }{@code >}
     * {@link JAXBElement }{@code <}{@link BigInteger }{@code >}
     * {@link JAXBElement }{@code <}{@link BigInteger }{@code >}
     * {@link JAXBElement }{@code <}{@link Boolean }{@code >}
     * {@link JAXBElement }{@code <}{@link Resource }{@code >}
     * {@link JAXBElement }{@code <}{@link Software }{@code >}
     * 
     * 
     */
    public List<JAXBElement<? extends Serializable>> getRest() {
        if (rest == null) {
            rest = new ArrayList<JAXBElement<? extends Serializable>>();
        }
        return this.rest;
    }

}

Why this annotations are ordered differently between 2 generations ? Is there a way to order them ?

Thanks !

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
user3560649
  • 91
  • 2
  • 3

1 Answers1

1

Author of the maven-jaxb2-plugin here.

First, Aleksandr M is perfectly right. Generated code is normally not checked into SCM. The whole target directory has nothing to do in git.

Next, the JAXB schema compiler (XJC) which is called by the maven-jaxb2-plugin is not deterministic, therefore the generated source code is not guaranteed to be identical between different code generations. This is definitely not an issue in the maven-jaxb2-plugin and I also won't call it a bug in XJC. Just lower your expectations, don't expect identical code between runs.

lexicore
  • 42,748
  • 17
  • 132
  • 221