生成有序的目录列表

时间:2013-12-18 10:19:48

标签: maven maven-assembly-plugin

我有一个由几个模块组成的项目(然后包含模块)。在完成整个构建之后,我使用maven-assembly-plugin将构建的分发组合在一起,包括我在部署文件时要运行的一些脚本。这些模块大多是包含一个或多个战争的耳朵文件。

程序集包含一个名称与ear项目同名的目录结构,它包含可部署的ear文件。到目前为止一切都很好,但是当我后来想要使用带脚本的构建文件时我有订单(由它们构建的顺序决定,这是模块在主pom中列出的顺序,很重要。我我们使用它们所在目录的时间戳尝试了这一点,但不幸的是,当我们将故障转移到另一台机器时,信息会丢失。即使是包含相同版本的压缩版本,我们公司范围内的时间戳也会丢失解压缩工具。

我的想法是生成ear文件所在目录的列表,并将它们放在文本文件或属性(逗号分隔)中,然后脚本可以读取这些目录以提供正确的顺序。

我的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
    .
    .
    .
    <modules>
        <module>SubProject1-Project/SubProject1-module</module>
        <module>SubProject2-Project/SubProject2-module</module>
        <module>SubProject3-Project/SubProject3-module</module>
        <module>SubProject4-Project/SubProject4-module</module>     
        <module>SubProject5-Project/SubProject5-module</module>
    </modules>
    <!-- Once all the modules are complete, the built packages are gathered up. -->
    <build>
        <finalName>${project.artifactId}-${project.version}-${maven.build.timestamp}</finalName>
        <plugins> 
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptors>
                        <descriptor>src/main/assembly/MyAssemblyDescriptor.xml</descriptor>
                    </descriptors>
                    <archive>
                        <manifest>                      
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>                     
                        </manifest>
                        <manifestEntries>
                            <Implementation-Version>${project.version}-${maven.build.timestamp}</Implementation-Version>
                            <Implementation-Build>${project.version}-${maven.build.timestamp}</Implementation-Build>
                        </manifestEntries>
                    </archive>                  
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>       
        </plugins>  
    </build>
</project>

MyAssemblyDescriptor.xml:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">

    <id>distribution</id>
    <formats>
        <format>dir</format>
        <format>zip</format>
    </formats>
    <moduleSets>
        <moduleSet>
            <sources>
                <fileSets>
                    <fileSet>
                        <outputDirectory>.</outputDirectory>
                        <directory>target</directory>
                        <includes>
                            <include>**/*.ear</include>
                            <include>**/*-distribution.zip</include>
                        </includes> 
                    </fileSet>      
                </fileSets>
            </sources>
        </moduleSet>
    </moduleSets>
    <includeBaseDirectory>false</includeBaseDirectory>  
</assembly>

这会产生一个目录文件结构:

SubProject1EAR\SubProject1EAR.ear
SubProject2EAR\SubProject2EAR.ear
SubProject3EAR\SubProject3EAR.ear
SubProject4EAR\SubProject4EAR.ear
SubProject5EAR\SubProject5EAR.ear

其中SubProject1EAR是SubProject1-module的子模块,上面是子模块。

基于所有这些,我想以正确的顺序生成EAR项目名称列表(也是每个EAR结束的目录的名称)。是否有任何maven插件或其他maven设置可以帮助我制作它?我试过看maven-assembly-plugin和maven reactor插件但找不到任何可以帮助我的东西。

0 个答案:

没有答案
相关问题