Maven 多个模块 - 打包后步骤
我有一个由多个模块组成的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试 Maven 程序集插件。
以下是 Maven 程序集插件示例。
Try the Maven Assembly Plugin.
Here are the Maven Assembly Plugin Examples.