6

I'm trying to configure maven-jaxb2-plugin to only generate java if XSD changes. That doesn't seem to work because java classes are always regenerated. This is the plugin configuration :

<plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.8.3</version>
            <configuration>
                <generateDirectory>${basedir}/src/main/java/</generateDirectory>
                <strict>true</strict>
                <verbose>true</verbose>
                <readOnly>true</readOnly>
                <episode>true</episode>
                <forceRegenerate>false</forceRegenerate>  
                <removeOldOutput>false</removeOldOutput>
            </configuration>
            <executions>
                <execution>
                    <id>commun-generate</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <generatePackage>my.package.dest</generatePackage>
                        <schemaDirectory>${basedir}/src/main/resources/schemas/wsrest</schemaDirectory>
                        <bindingDirectory>${basedir}/src/main/resources/schemas/wsrest</bindingDirectory>
                        <bindingIncludes>
                            <include>bindings.xml</include>
                        </bindingIncludes>
                        <episodeFile>${basedir}/src/main/java/META-INF/sun-jaxb_commun.episode</episodeFile>
                    </configuration>
                </execution>

When building (maven clean install or maven install) i can observe this output :

[INFO] File [D:\IDE\Data\Eclipse\workspace\MyProject\src\main\resources\schemas\wsrest\myXSD.xsd] was changed since the last build.
[INFO] File [D:\IDE\Data\Eclipse\workspace\MyProject\src\main\resources\schemas\wsrest\bindings.xml] was changed since the last build. 
[INFO] File [D:\IDE\Data\Eclipse\workspace\MyProject\pom.xml] was changed since the last build.

But i didn't change anything in theses files since the last build!

What am i doing wrong?

Thanks in advance

Clément

joeleclems
  • 131
  • 1
  • 9

3 Answers3

1

As a partial workaround you can add <noFileHeader>true</noFileHeader> to your configuration so that generated sources are the same for unchanged XSD. Solves my problems with repository commits, if that matters to you as well...

Can't stop XJC from re-generation it checks just timestamps it seems.

tomasb
  • 1,663
  • 2
  • 22
  • 29
1

There's no way to stop regenerate because of the following: I'd the same issue and I dug through the plugin code to find out the root cause:

The up-to-date check in org.jvnet.jaxb2.maven2.RawXJC2Mojo.isUpToDate uses if (getBuildContext().hasDelta(dependsFile)) which delegates to org.sonatype.plexus.build.incremental.DefaultBuildContext.hasDelta which is hard-coded to return true. This is because the concept of incremental build is broken in Maven c.f. Incremental Build

That logic can be changed to check if the output directory exists and if yes, if the XSD have changed. I may file a bug if I find time.

Abhijit Sarkar
  • 21,927
  • 20
  • 110
  • 219
0

Are the files actually regenerated? I have the following:

[INFO] File [C:\Projects\workspace-juno\maven-jaxb2-plugin-project\tests\po\src\main\resources\purchaseorder.xsd] was changed since the last build.
[INFO] File [C:\Projects\workspace-juno\maven-jaxb2-plugin-project\tests\po\pom.xml] was changed since the last build.
[INFO] Checking up-to-date depends [[C:\Projects\workspace-juno\maven-jaxb2-plugin-project\tests\po\src\main\resources\purchaseorder.xsd, C:\Projects\workspace-juno\maven-jaxb2-plugin-project\tests\po\pom.xml]].
[INFO] Checking up-to-date produces [[C:\Projects\workspace-juno\maven-jaxb2-plugin-project\tests\po\target\generated-sources\xjc\generated\Items.java, C:\Projects\workspace-juno\maven-jaxb2-plugin-project\tests\po\target\generated-sources\xjc\generated\ObjectFactory.java, C:\Projects\workspace-juno\maven-jaxb2-plugin-project\tests\po\target\generated-sources\xjc\generated\PurchaseOrderType.java, C:\Projects\workspace-juno\maven-jaxb2-plugin-project\tests\po\target\generated-sources\xjc\generated\USAddress.java, C:\Projects\workspace-juno\maven-jaxb2-plugin-project\tests\po\target\generated-sources\xjc\META-INF\sun-jaxb.episode]].
[INFO] Depends timestamp [1.395.259.386.093], produces timestamp [1.395.259.394.765].
[INFO] Skipped XJC execution. Generated sources were up-to-date.

It seems that the provided org.sonatype.plexus.build.incremental.BuildContext says that the file has changed. But when the plugin checks the timestamps specifically, it sees that files are up-to-date. I think the problem is just in the log message, it should read may have been changed.

Please file an issue here.

lexicore
  • 42,748
  • 17
  • 132
  • 221