从 Maven 项目生成发行版
我想用 Maven 构建一个应用程序发行版。我的项目中有一个模块,其中包含主要源代码。我决定从这个模块构建应用程序发行版。我在模块的 POM 中告诉 maven 将所有配置文件和依赖库复制到 target/
目录。我的问题是 Maven 将所有与构建相关的临时目录(如。classes
、generated-sources
、maven-archiver
)保留在目标目录中。我不想至少在安装
阶段自动删除它们。我怎样才能实现这个目标?如果我将 maven-clean-plugin
放在构建的末尾,看起来 Maven 总是会删除整个 target
目录,无论我试图排除谁的文件我想保留的东西。
I want to build an application distribution with Maven. I have a module in my project which holds the main source code. I decided to build the application distribution from this module. I'm telling maven in the module's POM to copy all the configuration files and dependant libs to the target/
directory. My problem is that Maven keeps all the build related temporary dirs (like. classes
, generated-sources
, maven-archiver
) in the target directory. I wan't to auto delete these at least during the install
phase. How can i achive this? If i put the maven-clean-plugin
to the end of the build it looks like Maven always deletes the whole target
directory, no matter who i'm trying to exclude files what i'm trying to keep.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在你的 pom 中尝试一下
,这是 xml
try this in your pom
and here is the xml
你是怎么做的?
根据这个问题,看起来您不需要担心有选择地删除目标文件夹的内容(这可以通过自定义 maven clean 插件),但使用 创建发行版maven 程序集插件 (如所指出的来自@Scorpion)。
后者允许您将所有项目工件(包括依赖项)捆绑在一起,形成 zip 或其他格式,然后开发人员可以轻松使用。您可能希望通过使用单独的
配置文件
将其与常规构建分离,以便仅根据需要构建发行版。How are you doing this?
Based on the question, it looks like you need to worry less about selectively deleting contents of target folder (which can be done by customizing maven clean plugin), but creating a distribution using maven assembly plugin (as pointed out by @Scorpion).
The latter allows you to bundle together all your project artifacts including the dependencies into zip or other formats, which can then be easily used by developers. You may want to decouple this from regular build by using a separate
profile
, so that the distribution is built only on need basis.