我正在尝试将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.
但自上次构建以来,我没有更改这些文件中的任何内容!
我做错了什么?
提前致谢
克莱门特
答案 0 :(得分:1)
作为部分解决方法,您可以将<noFileHeader>true</noFileHeader>
添加到配置中,以便生成的源对于未更改的XSD是相同的。解决我在存储库提交方面遇到的问题,如果这对你来说也很重要......
无法阻止XJC重新生成它只检查时间戳。
答案 1 :(得分:1)
由于以下因素,无法停止重新生成: 我遇到了同样的问题,我通过插件代码挖出了根本原因:
org.jvnet.jaxb2.maven2.RawXJC2Mojo.isUpToDate
中的最新一次检查使用if (getBuildContext().hasDelta(dependsFile))
代理org.sonatype.plexus.build.incremental.DefaultBuildContext.hasDelta
,该代码被硬编码以返回true。这是因为在Maven c.f中打破了增量构建的概念。 Incremental Build
可以更改该逻辑以检查输出目录是否存在,如果是,则更改XSD。如果我找时间,我可能会提交错误。
答案 2 :(得分: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
。
请提出问题here。