我正在使用 Maven 程序集插件来构建我们产品的 WAR(以前由 Ant 完成)。由于 Apache Ant 有很多遗留物,因此有一个特定要求可以使构建过程更容易:将依赖项的特定子文件夹(例如,jar 或 war 资源)复制到特定的目标子文件夹。
到目前为止,我了解到程序集描述符允许指定 <outputDirectory>
,但是否有机会指定 <sourceDirectory>
?例如,我想将此规则应用于单个 WAR 或 JAR 类型的依赖项。
考虑这个程序集描述符片段示例(不是 100% 准确):
<dependencySet>
<unpack>true</unpack>
<scope>runtime</scope>
<useProjectArtifact>false</useProjectArtifact>
<includes>
<include>my-specific-dependency:war</include>
</includes>
<outputDirectory>WEB-INF/myresources</outputDirectory>
</dependencySet>
我想说我想从 my-specific-dependency:war 复制一些文件夹到 WEB-INF/myresources。
编辑 注意:我知道这不是一个非常正确的要求,因为我们不应该知道 Artifact 内部是什么,正确的方法是声明将整个 Artifact 提取到目标目录(简洁的声明方法)。
最佳答案
您应该能够使用 Maven Dependency 插件来执行此操作,其解包目标是:
http://maven.apache.org/plugins/maven-dependency-plugin/unpack-mojo.html
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-database-scripts</id>
<phase>compile</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>myGroup</groupId>
<artifactId>myArtifact</artifactId>
<version>1.0</version>
<type>war</type>
<overWrite>true</overWrite>
<includes>...</includes>
<outputDirectory>…</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
关于Maven 程序集 : copy from specific sub-folder of dependency,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10278465/