我需要组装几组资源。这些资源集彼此相关。所以,我决定将它们全部放在同一个项目下,并使用程序集插件来实现我的目标。
我已经为每组资源的POM和描述符文件结束了。
我们假设我的项目如下:
descriptor1.xml的内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2
http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>set1</id>
<formats>
<format>tar.gz</format>
</formats>
<fileSets>
<fileSet>
<outputDirectory>/</outputDirectory>
<directory>${project.basedir}/src/main/resources/set1</directory>
</fileSet>
</fileSets>
</assembly>
descriptor2.xml和descriptor3.xml的内容类似于descriptor1.xml的内容,除了set1(在“/ assembly / id”和“/ assembly / fieldSets / fieldSet / directory”中)被set2替换分别为.3。
pom.xml的内容如下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sample</groupId>
<artifactId>sample.assembler</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<properties>
<maven-assembly-plugin.version>2.4</maven-assembly-plugin.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven-assembly-plugin.version}</version>
<executions>
<execution>
<id>set1</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>descriptor1.xml</descriptor>
</descriptors>
</configuration>
</execution>
<execution>
<id>set2</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>descriptor2.xml</descriptor>
</descriptors>
</configuration>
</execution>
<execution>
<id>set3</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>descriptor3.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
上面的配置给出了预期的结果。但是,要维护很多描述符文件。
我在文档中已经读到描述符文件在使用之前使用项目属性,POM元素值,用户属性......进行插值。
我的问题是:有没有办法引用当前执行的id(像project.build.execution.id这样的东西)?在这种情况下,我的所有三个描述符都只被一个文件替换。
提前谢谢。
答案 0 :(得分:1)
我认为你不能在单次运行中达到你想要的效果。
但您可以创建配置文件,其中配置文件的earch将定义不同的属性,您可以使用不同的配置文件运行您的构建三次以获得3个不同的文件集。
我确实使用这种方法为不同的环境生成配置。我激活环境配置文件,输出是环境配置。配置由单个描述符生成,该描述符由配置文件属性驱动。
修改强>
这是一个解决方法,使用每个执行的属性可以解决您的问题。目前我还不完全确定这些过滤器是否仅用于过滤资源,或者您可以在程序集本身中引用它们来定义让我们说<finalName>
...
请参阅:http://olafsblog.sysbsb.de/per-assembly-filtering-with-the-maven-assembly-plugin/