在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>发布于 2016-04-10 19:46:58
显然,maven-jaxb2-plugin不支持这样的特性。( maven-download-plugin甚至maven-dependency-plugin也不这么做)。
目前有三个解决方案出现在我的脑海中(加上两个半的灵感来自LIttle古森林的评论),数字反映了我所做的事情的优先级。
- Use the [GMavenPlus plugin](https://github.com/groovy/GMavenPlus) with a script ... [2]
- Use the [Maven AntRun plugin](https://maven.apache.org/plugins/maven-antrun-plugin/) with a script ... [3]
- Use the [Exec Maven plugin](http://www.mojohaus.org/exec-maven-plugin/) with a program ... [5]..。它执行下载、重试并将其绑定到项目POM中的generate-resources阶段。
- [Create a Maven plugin](https://maven.apache.org/guides/plugin/guide-java-plugin-development.html) with appropriate parameters (`url`, `outputDirectory`, `retryCount`) that uses the `maven-download-plugin` and performs the retry. Bind its goal to the `generate-resources` phase in your project's POM. [4]
- Create a `check-download` Maven project that uses the `maven-download-plugin` bound to the `generate-resources` phase to download the `.xsd`. [6]创建一个shell脚本,其中包含以下内容(伪代码):
下载: counter++ /mvn生成-资源的错误和计数器< maxRetryCount goto下载如果不是错误/mvn .否则显示适当的错误消息。
2005年的Maven下载重试?也有一个问题。没人回答。
发布于 2016-04-11 06:21:13
这里是maven-jaxb2-插件的作者。
这里有两个部分:管理外部资源的下载和编译模式,重写到本地文件的“外部”链接。
第一个(管理下载)不在maven-jaxb2-插件的范围内,第二个是由目录支持的。
简而言之,您可以创建如下目录文件:
REWRITE_SYSTEM "http://www.w3.org" "w3c"或者这个:
REWRITE_SYSTEM "http://schemas.opengis.net" "maven:org.jvnet.ogc:ogc-schemas:jar::!/ogc"并使用此文件“重写”Maven工件中的本地文件或资源的绝对链接:
<configuration>
<catalog>src/main/resources/catalog.cat</catalog>
</configuration>至于第一部分,我不认为使用重试、延续和所有其他内容来管理下载应该在JAXB2 Maven插件的范围内。
ps。您不需要build-helper-maven-plugin/add-source和maven-jaxb2-plugin,源目录会自动添加。
https://stackoverflow.com/questions/36533102
复制相似问题