带有 maven- assembly-plugin 的多个文件 --> “已添加,跳过”

发布于 2024-12-26 17:29:19 字数 5498 浏览 2 评论 0原文

我需要在按环境的 tar 包中创建多个 tar 文件。

每个不同的环境都有一个包含唯一文件“environment.properties”的文件夹,因此我必须将项目内容与每个环境的environment.properties 文件合并:RC、BC、PROD。

我使用 maven- assembly-plugin 来执行此操作,因此有 3 个与该程序集类似的程序集描述符,具有不同的“id”:

<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>pack-content-rc</id>
    <includeBaseDirectory>false</includeBaseDirectory>
    <formats>
        <format>tar</format>
    </formats>
    <fileSets>
        <fileSet>
            <outputDirectory>/definitions</outputDirectory>
            <directory>definitions</directory>
            <includes>
                <include>*.*</include>
            </includes>
            <excludes>
                <exclude>.*</exclude>
            </excludes>
        </fileSet>
        <fileSet>
            <outputDirectory>/library</outputDirectory>
            <directory>library</directory>
            <includes>
                <include>*.*</include>
            </includes>
            <excludes>
                <exclude>.*</exclude>
            </excludes>
        </fileSet>
        <fileSet>
            <outputDirectory>/messages</outputDirectory>
            <directory>messages</directory>
            <includes>
                <include>*.*</include>
            </includes>
            <excludes>
                <exclude>.*</exclude>
            </excludes>
        </fileSet>
        <fileSet>
            <outputDirectory>/templates</outputDirectory>
            <directory>templates</directory>
            <includes>
                <include>**/*</include>
            </includes>
            <excludes>
                <exclude>.*</exclude>
            </excludes>
        </fileSet>
        <fileSet>
            <outputDirectory>/variables</outputDirectory>
            <directory>variables</directory>
            <includes>
                <include>*.*</include>
            </includes>
            <excludes>
                <exclude>.*</exclude>
            </excludes>
        </fileSet>
        <fileSet>
            <outputDirectory>/variables</outputDirectory>
            <directory>target/escape/rc</directory>
            <includes>
                <include>*.*</include>
            </includes>
        </fileSet>      
    </fileSets>
</assembly>

插件的 Maven 配置为:

...
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.2</version>
<executions>
    <execution>
        <id>make-assembly</id>
        <phase>package</phase>
        <goals>
            <goal>single</goal>
        </goals>
        <configuration>
            <descriptors>
                <descriptor>pack-content-rc.xml</descriptor>
                <descriptor>pack-content-bc.xml</descriptor>
                <descriptor>pack-content-prod.xml</descriptor>
            </descriptors>
        </configuration>
    </execution>
</executions>
...

输出日志为:

[INFO] --- maven-assembly-plugin:2.2.2:single (make-assembly) @ nibbler-content ---
[INFO] Reading assembly descriptor: pack-content-rc.xml
[INFO] Reading assembly descriptor: pack-content-bc.xml
[INFO] Reading assembly descriptor: pack-content-prod.xml
[INFO] nibbler-content-19.0.1-SNAPSHOT-rc/variables/environment.properties already added, skipping
[INFO] Building tar : /Users/ger/Documents/Work/nibbler-content/target/nibbler-content-19.0.1-SNAPSHOT-pack-content-rc.tar
[INFO] nibbler-content-19.0.1-SNAPSHOT-rc/variables/environment.properties already added, skipping
[INFO] nibbler-content-19.0.1-SNAPSHOT-bc/variables/environment.properties already added, skipping
[INFO] Building tar : /Users/ger/Documents/Work/nibbler-content/target/nibbler-content-19.0.1-SNAPSHOT-pack-content-bc.tar
[INFO] nibbler-content-19.0.1-SNAPSHOT-bc/variables/environment.properties already added, skipping
[INFO] nibbler-content-19.0.1-SNAPSHOT-prod/variables/environment.properties already added, skipping
[INFO] Building tar : /Users/ger/Documents/Work/nibbler-content/target/nibbler-content-19.0.1-SNAPSHOT-pack-content-prod.tar
[INFO] nibbler-content-19.0.1-SNAPSHOT-prod/variables/environment.properties already added, skipping
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

问题是 3生成的文件具有相同的environment.properties 文件,确切地说是第一个文件,所以我最终得到了3 个完全相同的包的文件。

我假设组装过程使用一个目录来组成 tar,因此它复制第一个文件,对于第二个描述符,该文件已经存在......

有没有办法避免这种情况发生?在运行每个描述符之前进行一些清理? 我应该使用 maven-ant-run 插件还是类似的东西?

谢谢!

I need to create multiple tar files in a tar-by-environment package.

Every different environment has a folder with an only file "environment.properties", so I've got to merge the project content with the environment.properties file for each of my environments: RC, BC, PROD.

I'm using maven-assembly-plugin to do this, so there are 3 assembly descriptors similar to this assembly with different "id":

<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>pack-content-rc</id>
    <includeBaseDirectory>false</includeBaseDirectory>
    <formats>
        <format>tar</format>
    </formats>
    <fileSets>
        <fileSet>
            <outputDirectory>/definitions</outputDirectory>
            <directory>definitions</directory>
            <includes>
                <include>*.*</include>
            </includes>
            <excludes>
                <exclude>.*</exclude>
            </excludes>
        </fileSet>
        <fileSet>
            <outputDirectory>/library</outputDirectory>
            <directory>library</directory>
            <includes>
                <include>*.*</include>
            </includes>
            <excludes>
                <exclude>.*</exclude>
            </excludes>
        </fileSet>
        <fileSet>
            <outputDirectory>/messages</outputDirectory>
            <directory>messages</directory>
            <includes>
                <include>*.*</include>
            </includes>
            <excludes>
                <exclude>.*</exclude>
            </excludes>
        </fileSet>
        <fileSet>
            <outputDirectory>/templates</outputDirectory>
            <directory>templates</directory>
            <includes>
                <include>**/*</include>
            </includes>
            <excludes>
                <exclude>.*</exclude>
            </excludes>
        </fileSet>
        <fileSet>
            <outputDirectory>/variables</outputDirectory>
            <directory>variables</directory>
            <includes>
                <include>*.*</include>
            </includes>
            <excludes>
                <exclude>.*</exclude>
            </excludes>
        </fileSet>
        <fileSet>
            <outputDirectory>/variables</outputDirectory>
            <directory>target/escape/rc</directory>
            <includes>
                <include>*.*</include>
            </includes>
        </fileSet>      
    </fileSets>
</assembly>

And the maven configuration of the plugin is:

...
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.2</version>
<executions>
    <execution>
        <id>make-assembly</id>
        <phase>package</phase>
        <goals>
            <goal>single</goal>
        </goals>
        <configuration>
            <descriptors>
                <descriptor>pack-content-rc.xml</descriptor>
                <descriptor>pack-content-bc.xml</descriptor>
                <descriptor>pack-content-prod.xml</descriptor>
            </descriptors>
        </configuration>
    </execution>
</executions>
...

And the output log is:

[INFO] --- maven-assembly-plugin:2.2.2:single (make-assembly) @ nibbler-content ---
[INFO] Reading assembly descriptor: pack-content-rc.xml
[INFO] Reading assembly descriptor: pack-content-bc.xml
[INFO] Reading assembly descriptor: pack-content-prod.xml
[INFO] nibbler-content-19.0.1-SNAPSHOT-rc/variables/environment.properties already added, skipping
[INFO] Building tar : /Users/ger/Documents/Work/nibbler-content/target/nibbler-content-19.0.1-SNAPSHOT-pack-content-rc.tar
[INFO] nibbler-content-19.0.1-SNAPSHOT-rc/variables/environment.properties already added, skipping
[INFO] nibbler-content-19.0.1-SNAPSHOT-bc/variables/environment.properties already added, skipping
[INFO] Building tar : /Users/ger/Documents/Work/nibbler-content/target/nibbler-content-19.0.1-SNAPSHOT-pack-content-bc.tar
[INFO] nibbler-content-19.0.1-SNAPSHOT-bc/variables/environment.properties already added, skipping
[INFO] nibbler-content-19.0.1-SNAPSHOT-prod/variables/environment.properties already added, skipping
[INFO] Building tar : /Users/ger/Documents/Work/nibbler-content/target/nibbler-content-19.0.1-SNAPSHOT-pack-content-prod.tar
[INFO] nibbler-content-19.0.1-SNAPSHOT-prod/variables/environment.properties already added, skipping
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

The problem is that the 3 resulting files have the same environment.properties file, the first file to be exact, so I end up having 3 files that are exactly the same package.

I assume that the assembly process uses a directory to compose the tar, so it copies the first file, and for the second descriptor the file is already there...

Is there a way to avoid this to happend? Something like a clean before running each descriptor?
Should I use maven-ant-run plugin or something like that?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三五鸿雁 2025-01-02 17:29:19

已添加,跳过 的事情首先出现在插件的 2.2 版本中,您可以尝试 v2.1。

The already added, skipping thing came first with version 2.2 of the plugin, you may try v2.1.

梦太阳 2025-01-02 17:29:19

通常,一个 Maven 工件意味着一个输出文件。也许为每个 tar 制作 3 个独立的 Maven 模块更有意义。此外,它还提供了更多的灵活性。

Usually one maven artifact means exactly one output file. Maybe it has more sense to make 3 separate maven modules for each tar. Moreover it gives more flexibility.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文