我是 Maven 的新手,我想我已经开始了解它是如何工作的了。但我无法理解 maven 程序集插件。我想要实现的是:
当所有项目都打包后,以及它们各自的依赖项,我希望将它们全部放在目标目录中。我不希望将它们打包到一个 super jar 中,因为该系统是基于模块的。
让我解释一下,我有一个主项目,服务器,在 maven 项目“common”中,我有两个模块,“core”和“android”。在 common 文件夹中,还有一个我想要复制的 conf 文件夹。我想要这个结构:
我的项目结构是这样的:
感谢您的任何帮助,或以正确的方式提供指导。 :)
编辑 这是 100% 工作的 ant 构建文件,也许我应该保留它?
<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 项目的 Artifact 、依赖项和其他相关文件的 tar 或 zip 存档变得非常容易。
听起来您只需要 set up the assembly plugin使用自定义描述符来拉入您感兴趣的 jars 和配置文件。如果您有一个代表“可分发”事物的模块——即使该模块依赖于其他模块——那么你可能只是添加一个 assembly descriptor其中包括一些 files , fileSets , 和/或 dependencySets .
如果您的项目中有多个模块需要包含并且没有任何依赖于所有模块,那么您需要查看 moduleSets .我自己从来没有使用过这些,但它们正是为了解决这个问题。
关于具有特殊结构的多模块项目的Maven组装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10787101/