Maven 多个模块 - 打包后步骤

发布于 2024-09-15 19:13:12 字数 2744 浏览 3 评论 0原文

我有一个由多个模块组成的 Maven 项目。我有一个 POM 文件,用于调用所有依赖模块的构建。我想要做的是在所有子模块的包生命周期完成后,将一堆文件复制到一个位置并将它们压缩一次。

我研究过 antrun,但不知道如何让它运行一次。目前它在每个模块的打包阶段运行。这是我的父 POM 文件(简化)

<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<name>project</name>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
    <module>../module1</module>
    <module>../module2</module>
</modules>
<dependencies>
    ...
</dependencies>
<build>
    <plugins>
        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <configuration>
                        <tasks>
                            <mkdir dir="product" />
                            <copy todir="product">
                                <fileset dir="../module1/doc/release">
                                    <include name="*.pdf" />
                                </fileset>
                                <fileset dir="../module2/doc/release">
                                    <include name="*.pdf" />
                                </fileset>
                                <fileset dir="../module1/target">
                                    <include name="*.war" />
                                </fileset>
                                <fileset dir="../module2/target">
                                    <include name="*.war" />
                                </fileset>
                            </copy>
                            <copy file="app.properties" todir="cesium" />

                            <zip basedir="product" destfile="dist.zip"></zip>

                        </tasks>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>

<properties>
    ...
</properties>

希望我想做什么很清楚。我只希望 antrun 任务在包生命周期之后发生,并且只发生一次,而不是针对每个模块。

我知道我可能没有以正确的方式完成这一步,但我不清楚如何最好地使用 Maven 来完成这一步。任何想法表示赞赏。

I have a Maven project that consists of several modules. I have a single POM file that I use to invoke the build of all dependent modules. What I want to do is to copy a bunch of files to a single location and zip them up once, after the package lifecycle of all the sub-modules has completed.

I've looked into antrun, but can't see how to make it run once. Currently it runs during the package phase of each module. Here's my parent POM file (simplified)

<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<name>project</name>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
    <module>../module1</module>
    <module>../module2</module>
</modules>
<dependencies>
    ...
</dependencies>
<build>
    <plugins>
        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <configuration>
                        <tasks>
                            <mkdir dir="product" />
                            <copy todir="product">
                                <fileset dir="../module1/doc/release">
                                    <include name="*.pdf" />
                                </fileset>
                                <fileset dir="../module2/doc/release">
                                    <include name="*.pdf" />
                                </fileset>
                                <fileset dir="../module1/target">
                                    <include name="*.war" />
                                </fileset>
                                <fileset dir="../module2/target">
                                    <include name="*.war" />
                                </fileset>
                            </copy>
                            <copy file="app.properties" todir="cesium" />

                            <zip basedir="product" destfile="dist.zip"></zip>

                        </tasks>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>

<properties>
    ...
</properties>

Hopefully it's clear what I'm trying to do. I just want the antrun task to happen after the package lifecycle, and only once, not for each module.

I understand that I might not be approaching this step the right way, but I'm unclear how best to aproach this with Maven. Any thoughts appreciated.

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

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

发布评论

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

评论(1

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