【发布时间】:2014-08-21 01:40:25
【问题描述】:
设置
我有一个尝试使用 Maven 构建的复杂项目。以下是该项目的简化示例。目录结构如下:
- main - 该项目有多个“耳朵”,每个“耳朵”包含多个“战争”以及其他支持的 jar。然而,它们共享一组通用的 WSDL/XSD 以及 Java 代码。
- pom.xml - 这是主要的 pom.xml 文件,我将在下面更详细地描述它。
- common-code-one - 两个 'ear' 包有一个共同的代码体,只是 java 代码,没有 wsdl,没有 xsd,所以没问题。
- wsdl - 包含所有 XSD 和 WSDL 文件的单个包,它有一个 pom.xml,可以简单地将其全部打包到一个 jar 文件中,以供以后在子目录中使用。
- 耳包一
- common-code-two - 来自“wsdl”的一些 XSD 在此处解压缩,并通过 jaxb2 转换为代码。作为其中的一部分,会生成一个剧集文件。
- war-package-one - 更多的 XSD 和 WSDL 文件在此处解压缩,并通过 jaxws 转换为代码。为避免重复代码,我需要来自“common-code-two”的剧集文件,并且我需要来自“wsdl”的 XSD/WSDL 文件。
- war-package-two - 不同的 XSD/WSDL,但我仍然需要来自 common-code-2 的剧集文件,以及来自“wsdl”的 XSD/WSDL。
- ejb-package-one - 不需要“wsdl”中的任何内容,但可能需要“common-code-two”中的一些代码,而不需要剧集文件。
- ...
- 耳包二
- common-code-two - 同样的问题,不同的 XSD。
- ejb-package-two - 同样的问题,不同的代码。
- war-package-three - 同样的问题,不同的 XSD/WSDL。
- war-package-four - 同样的问题,不同的 XSD/WSDL。
现在,主要的“pom.xml”文件。遵循 Maven 的 DRY 原则,我将 maven-dependency-plugin 的两个执行都放入了主 pom.xml。问题是,在上面的某些子包中,我只希望运行“解包模式”执行,而在其他一些子包中,我希望 both '解包模式'和'解包常见-绑定'运行。当然,对于那些都不需要的,我只是不将依赖插件添加到构建列表中。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-schema</id>
<phase>generate-sources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.foo.bar</groupId>
<artifactId>wsdl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}</outputDirectory>
<includes>${schema.include.list}</includes>
</artifactItem>
</artifactItems>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
<execution>
<id>unpack-common-binding</id>
<phase>generate-sources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.foo.bar</groupId>
<artifactId>${common.code.jar}</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}</outputDirectory>
<includes>**/commonCode.xml</includes>
</artifactItem>
</artifactItems>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
问题
我应该在子项目的 pom.xml 文件中添加什么以便只执行所需的执行?
如果我简单地输入
<build>
<plugins>
...
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
...
</plugins>
</build>
然后两次执行都会发生。在“战争”包中,没关系,这就是我想要发生的事情,但在“通用代码”包中,我只希望发生“解包模式”执行。
我见过this question,但它从来没有真正得到回答,并且评论的解决方案(运行多个构建)只是不适合我的环境。这将经历持续集成/构建,因此必须直接编译。无需脚本,无需多次构建。
【问题讨论】:
标签: java maven xsd wsdl maven-dependency-plugin