在 maven 中处理 xsd 依赖项时抛出 IOException
IOException thrown when processing xsd dependencies in maven
我在 maven 构建过程中处理 .xsd 文件时遇到问题。
我使用 jaxb2 插件,但我必须从我的 .xsd 文件下载外部依赖项。问题是这些依赖项 (.xsd) 来自不稳定的环境,而且我的构建经常失败,因为 Maven 无法下载 xsd 文件。如何配置 jaxb 插件强制他尝试下载 xsd 几次以防止构建失败?
我的部分 pom.xml 配置:
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<configuration>
<strict>false</strict>
<extension>true</extension>
<args>
<arg>-Xfluent-api</arg>
<arg>-XtoString</arg>
<arg>-Xsetters</arg>
<arg>-XenumValue</arg>
</args>
<plugins>
<plugin>
<groupId>net.java.dev.jaxb2-commons</groupId>
<artifactId>jaxb-fluent-api</artifactId>
<version>${jaxb.fluentapi.version}</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.9.3</version>
</plugin>
</plugins>
<bindingDirectory>src/main/resources/jaxb</bindingDirectory>
<bindingIncludes>
<include>bindings.xml</include>
</bindingIncludes>
<schemas>
<schema>
<fileset>
<!-- Defaults to schemaDirectory. -->
<directory>${project.basedir}/src/main/resources/orbeons</directory>
<!-- Defaults to schemaIncludes. -->
<includes>
<include>*.xsd</include>
</includes>
</fileset>
</schema>
</schemas>
</configuration>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.basedir}/generated-sources/orbeons</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
显然 maven-jaxb2-plugin
does not support such a feature. (And neither does the maven-download-plugin
nor even the maven-dependency-plugin
).
此刻我想到了三个解决方案(加上受 LIttle Ancient Forest Kami 评论启发的两个半)[数字反映了我将要做的事情的优先级]:
使用支持作业失败重试的 CI 工具(Jenkins 等)。 [1]
手工制作:
使用脚本 GMavenPlus plugin ... [2]
使用脚本 Maven AntRun plugin ... [3]
将Exec Maven plugin与程序一起使用...[5]
... 执行下载并重试并将其绑定到项目 POM 中的 generate-resources
阶段。
Create a Maven plugin 具有适当的参数(url
、outputDirectory
、retryCount
),使用 maven-download-plugin
并执行重试。将其目标绑定到项目 POM 中的 generate-resources
阶段。 [4]
创建一个check-download
Maven项目,使用绑定到generate-resources
阶段的maven-download-plugin
下载.xsd
。 [6]
创建一个包含以下内容(伪代码)的 shell 脚本:
download:
counter++
<check-download project>/mvn generate-resources
if error and counter < maxRetryCount goto download
if not error
<your project>/mvn ...
else
display appropriate error message
还有一个问题 Maven download retry? 来自 2005 年。未回答。
maven-jaxb2-plugin 的作者在这里。
您在这里有两个部分:管理外部资源的下载和编译模式,重写 "external" 到本地文件的链接。
第一个(管理下载)不在 maven-jaxb2-plugin 的范围内,第二个受支持
catalogs.
简而言之,您可以像这样创建目录文件:
REWRITE_SYSTEM "http://www.w3.org" "w3c"
或者这样:
REWRITE_SYSTEM "http://schemas.opengis.net" "maven:org.jvnet.ogc:ogc-schemas:jar::!/ogc"
并使用此文件 "rewrite" 到 Maven 工件中本地文件或资源的绝对链接:
<configuration>
<catalog>src/main/resources/catalog.cat</catalog>
</configuration>
至于第一部分,我认为使用重试、继续和所有其他内容管理下载不应该在 JAXB2 Maven 插件的范围内。
ps。您不需要 build-helper-maven-plugin/add-source
和 maven-jaxb2-plugin
,源目录会自动添加。
我在 maven 构建过程中处理 .xsd 文件时遇到问题。 我使用 jaxb2 插件,但我必须从我的 .xsd 文件下载外部依赖项。问题是这些依赖项 (.xsd) 来自不稳定的环境,而且我的构建经常失败,因为 Maven 无法下载 xsd 文件。如何配置 jaxb 插件强制他尝试下载 xsd 几次以防止构建失败?
我的部分 pom.xml 配置:
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<configuration>
<strict>false</strict>
<extension>true</extension>
<args>
<arg>-Xfluent-api</arg>
<arg>-XtoString</arg>
<arg>-Xsetters</arg>
<arg>-XenumValue</arg>
</args>
<plugins>
<plugin>
<groupId>net.java.dev.jaxb2-commons</groupId>
<artifactId>jaxb-fluent-api</artifactId>
<version>${jaxb.fluentapi.version}</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.9.3</version>
</plugin>
</plugins>
<bindingDirectory>src/main/resources/jaxb</bindingDirectory>
<bindingIncludes>
<include>bindings.xml</include>
</bindingIncludes>
<schemas>
<schema>
<fileset>
<!-- Defaults to schemaDirectory. -->
<directory>${project.basedir}/src/main/resources/orbeons</directory>
<!-- Defaults to schemaIncludes. -->
<includes>
<include>*.xsd</include>
</includes>
</fileset>
</schema>
</schemas>
</configuration>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.basedir}/generated-sources/orbeons</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
显然 maven-jaxb2-plugin
does not support such a feature. (And neither does the maven-download-plugin
nor even the maven-dependency-plugin
).
此刻我想到了三个解决方案(加上受 LIttle Ancient Forest Kami 评论启发的两个半)[数字反映了我将要做的事情的优先级]:
使用支持作业失败重试的 CI 工具(Jenkins 等)。 [1]
手工制作:
使用脚本 GMavenPlus plugin ... [2]
使用脚本 Maven AntRun plugin ... [3]
将Exec Maven plugin与程序一起使用...[5]
... 执行下载并重试并将其绑定到项目 POM 中的
generate-resources
阶段。Create a Maven plugin 具有适当的参数(
url
、outputDirectory
、retryCount
),使用maven-download-plugin
并执行重试。将其目标绑定到项目 POM 中的generate-resources
阶段。 [4]创建一个
check-download
Maven项目,使用绑定到generate-resources
阶段的maven-download-plugin
下载.xsd
。 [6]创建一个包含以下内容(伪代码)的 shell 脚本:
download: counter++ <check-download project>/mvn generate-resources if error and counter < maxRetryCount goto download if not error <your project>/mvn ... else display appropriate error message
还有一个问题 Maven download retry? 来自 2005 年。未回答。
maven-jaxb2-plugin 的作者在这里。
您在这里有两个部分:管理外部资源的下载和编译模式,重写 "external" 到本地文件的链接。
第一个(管理下载)不在 maven-jaxb2-plugin 的范围内,第二个受支持 catalogs.
简而言之,您可以像这样创建目录文件:
REWRITE_SYSTEM "http://www.w3.org" "w3c"
或者这样:
REWRITE_SYSTEM "http://schemas.opengis.net" "maven:org.jvnet.ogc:ogc-schemas:jar::!/ogc"
并使用此文件 "rewrite" 到 Maven 工件中本地文件或资源的绝对链接:
<configuration>
<catalog>src/main/resources/catalog.cat</catalog>
</configuration>
至于第一部分,我认为使用重试、继续和所有其他内容管理下载不应该在 JAXB2 Maven 插件的范围内。
ps。您不需要 build-helper-maven-plugin/add-source
和 maven-jaxb2-plugin
,源目录会自动添加。