具有特殊结构的Maven装配在多模块项目上 [英] Maven assembly on multi module project with special structure

查看:87
本文介绍了具有特殊结构的Maven装配在多模块项目上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Maven的新手,我想我已经开始了解它的工作原理.但是我无法理解Maven程序集插件.我想实现的是这样:

I'm new to Maven, and I think I've started to get the idea of how it works. But I'm not able to understand the maven assembly plugin. What I want to achieve is this:

打包所有项目以及它们各自的依赖关系后,我希望将它们全部保存在目标目录中.我不希望将它们打包到一个超级jar中,因为系统是基于模块的.

When all projects has been packaged, with their respective dependencies, I want to have them all in the target directory. I don't want them to be packaged into one super-jar because the system is based on modules.

让我解释一下,我在maven项目"common"中有一个主项目,即服务器,还有两个模块,"core"和"android".在common文件夹中,还有一个我要复制的conf文件夹.我想要这样的结构:

Let me explain, I have a main project, the server, in the maven project "common", and I have two modules, "core" and "android". In the common folder, there is also a conf folder that I want copied over. I want this structure:

  • target/common.jar
  • target/conf/(配置文件)
  • target/modules/core.jar
  • target/modules/android.jar
  • target/common.jar
  • target/conf/(configuration files)
  • target/modules/core.jar
  • target/modules/android.jar

我的项目结构是这样:

  • pom.xml(父项目)
  • common/(Maven模块)
  • 核心/(maven模块)
  • android/(maven模块)

感谢您的任何帮助,或以正确的方式提出了建议. :)

Thank you for any help, or pointers in the right way. :)

编辑:这是100%有效的ant构建文件,也许我应该坚持下去?

EDIT Here is the ant build file which works 100%, maybe I should keep with that?

<target name="init">
    <mkdir dir="dist" />
    <mkdir dir="dist/conf/" />
    <mkdir dir="dist/modules/" />
    <mkdir dir="dist/libs/" />

    <copy includeemptydirs="false" todir="dist/conf">
        <fileset dir="common/conf" />
    </copy>
</target>

<target name="copy-server">
    <copy todir="dist">
        <fileset file="common/target/server*.jar" />
    </copy>
</target>

<target name="copy-modules">
    <copy todir="dist/modules/">
        <fileset file="core/target/*.jar" />
        <fileset file="android/target/*.jar" />
    </copy>
</target>

<target name="copy-libs">
    <copy todir="dist/libs">
        <fileset dir="common/target/libs" />
        <fileset dir="core/target/libs" />
        <fileset dir="android/target/libs" />
    </copy>
    <delete>
        <fileset file="dist/libs/server*.jar" />
    </delete>
</target>

<target name="clean">
    <delete dir="dist" />
</target>

<target name="full-build" depends="clean, init, copy-server, copy-libs, copy-modules, increment">
    <echo message="Copying the fully built Maven project" />
</target>

<target name="increment">
    <propertyfile file="common/conf/version.properties">
        <entry key="build.number" type="int" operation="+" default="0" />
    </propertyfile>
    <property file="common/conf/version.properties" />
    <echo message="Build number is ${build.number}"/>
</target>

推荐答案

首先,程序集插件的作用:制作包含Maven项目的工件,依赖项和其他内容的tar或zip存档确实非常容易.相关文件.

First, what the assembly plugin does: it makes it really easy to make a tar or zip archive containing a Maven project's artifact(s), dependencies, and other related files.

听起来您需要做的只是设置程序集插件带有自定义描述符,以提取您感兴趣的jar和配置文件.如果您有一个表示可分发"事物的模块-即使该模块依赖于其他模块-那么您d可能只是向其中添加一个程序集描述符,其中包括一些文件

It sounds like all you need to do is set up the assembly plugin with a custom descriptor to pull in the jars and config files you're interested in. If you have a single module that represents a "distributable" thing--even if that module depends on other modules--then you'd probably just add an assembly descriptor to it that includes some files, fileSets, and/or dependencySets.

如果您的项目中要包含多个模块,而没有任何模块依赖于所有模块,那么您需要查看

If there are several modules in your project that you want to include and there's nothing that depends on all of them, then you'd want to look at moduleSets. I've never had to use those myself, but they're for exactly that problem.

这篇关于具有特殊结构的Maven装配在多模块项目上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆