6

我正在尝试将 maven-jaxb2-plugin 配置为仅在 XSD 更改时生成 java。这似乎不起作用,因为总是重新生成 java 类。这是插件配置:

<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>

构建时(maven clean install 或 maven install)我可以观察到这个输出:

[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.

但是自上次构建以来,我没有更改这些文件中的任何内容!

我究竟做错了什么?

提前致谢

克莱门特

4

3 回答 3

1

作为部分解决方法,您可以添加<noFileHeader>true</noFileHeader>到您的配置中,以便生成的源对于未更改的 XSD 是相同的。解决我的存储库提交问题,如果这对您也很重要......

无法阻止 XJC 重新生成它似乎只检查时间戳。

于 2015-05-13T09:15:52.797 回答
1

由于以下原因,无法停止重新生成:我遇到了同样的问题,我挖掘了插件代码以找出根本原因:

最新签入org.jvnet.jaxb2.maven2.RawXJC2Mojo.isUpToDate使用硬编码的if (getBuildContext().hasDelta(dependsFile))委托来返回 true。org.sonatype.plexus.build.incremental.DefaultBuildContext.hasDelta这是因为增量构建的概念在 Maven cf Incremental Build中被打破

可以更改该逻辑以检查输出目录是否存在,如果存在,则 XSD 是否已更改。如果我有时间,我可能会提交错误。

于 2015-10-22T18:56:39.043 回答
0

文件是否真的重新生成了?我有以下内容:

[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.

提供的似乎表明org.sonatype.plexus.build.incremental.BuildContext文件已更改。但是当插件专门检查时间戳时,它会发现文件是最新的。我认为问题只是在日志消息中,它应该是may have been changed.

在此处提出问题。

于 2014-03-19T20:09:30.057 回答