从包含多个可选模块的 Maven 项目构建任意发行版
首先:我的 Maven 知识有限,所以请耐心等待。 ;-) 我有一个简单的 Maven 项目,当前由三个模块组成。包含应用程序核心的模块称为 core(创意名称,嗯?:-)),其他模块基本上都是该核心模块的插件。有一个限制:核心模块中只能添加一个插件。
核心模块有自己的 Spring IoC 配置,减去插件配置。这非常简单:核心代码将读取一个名为“plugin”的 bean,该 bean 未在核心配置中定义。插件模块将提供自己的配置文件,该文件将提供一个名为“plugin”的 bean,然后由核心代码使用。这非常适合我的用例。
我想提供将部署系统的管理员,一种构建包含核心、选定的插件和合理的默认配置的发行版的简单方法。也许是 tar.gz
或类似的东西。我不想让他挖掘我的 Spring IoC 文件,将它们复制在一起等等。像 TCP/IP 端口这样的实际配置是在属性文件中完成的。
为了澄清我的意思,我构建了一个示例结构。请注意,文件名仅用于说明目的。
/bin/core.jar [Build from core module] /bin/plugin.jar [Build from a plugin module] /lib-bin/library-required-by-plugin.jar [Dependency resolved by maven + copy] /lib-bin/library-required-by-core.jar [Dependency resolved by maven + copy] /lib-bin/another-library-required-by-core.jar [Dependency resolved by maven + copy] /etc/spring/core-beans.xml [Copied from core module /etc/] /etc/spring/plugin.xml [Copied from plugin module /etc/] /etc/default-core-config.properties [Copied from core module /etc/] /etc/default-plugin-config.properties [Copied from plugin module /etc/]
我目前正在摆弄组装插件,但我似乎在兜圈子,没有任何效果。相当令人沮丧。如果您需要更多信息或不明白我的观点,请随时询问。 :-)
另外澄清我的问题:如何做到这一点? (嗯,就这么简单:-))正如我之前所说,我对 Maven 的了解是有限的,目前我一无所获,即使我知道程序集插件可能是可行的方法。特别是如何从每个模块获取依赖项,在哪里配置插件(在父项目中?),甚至一点程序集描述符都会有很大帮助。
感谢您的所有意见!
first of all: my Maven knowledge is limited so please bear with me. ;-) I have a simple Maven Project currently consisting of three modules. The module containing the core of the application is called core (Creative name, huh? :-)) and the other modules are basically plugins for this core module. There is one restriction: Only one plugin can be added to the core module.
The core module has its own Spring IoC configuration minus the plugin configuration. This is quite simple: The core code will read a bean named "plugin" which is not defined in the core configuration. The plugin modules will ship their own configuration files which will supply a bean named "plugin" which is then used by the core code. This fits perfectly in my use-case.
I want to provide the Admin, which will deploy the system, a simple way to build a distribution containing the core, a selected plugin and a reasonable default configuration. Maybe a tar.gz
or something like that. I don't want him to dig though my Spring IoC files, copy them together, etc. etc. The actual configuration like TCP/IP ports are done in property files.
To clarify what i mean I've build an example structure. Note that the filenames are for explanation purposes only.
/bin/core.jar [Build from core module] /bin/plugin.jar [Build from a plugin module] /lib-bin/library-required-by-plugin.jar [Dependency resolved by maven + copy] /lib-bin/library-required-by-core.jar [Dependency resolved by maven + copy] /lib-bin/another-library-required-by-core.jar [Dependency resolved by maven + copy] /etc/spring/core-beans.xml [Copied from core module /etc/] /etc/spring/plugin.xml [Copied from plugin module /etc/] /etc/default-core-config.properties [Copied from core module /etc/] /etc/default-plugin-config.properties [Copied from plugin module /etc/]
I currently mess around with the assembly plugin but i seem to go round in circles and nothing works. Pretty frustrating. If you need any more information or do not get my point feel free to ask. :-)
Addition to clarify my question: How to do that? (Well, its just that simple :-)) As I stated before, my knowledge of Maven is limited and currently i'm getting nowhere, even if I know that the assembly plugin might be the way to go. Especially how to get the dependencies from each module, where to configure the plugin (In the parent project?) and even a bit of an assembly descriptor would help a lot.
Thank you for all your input!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用程序集插件来打包命令行应用程序的发行版,如下所示:
这包括将插件绑定到 构建生命的包阶段 -循环
<块引用>
mvn 程序集:程序集
mvn包
mvn安装
mvn部署
I used the assembly plugin to package a distribution of a command line application as follows:
this includes binding the plugin to the package phase of the build life-cycle
如果您只是期待确认,那么我确认您所描述的情况是 Maven 程序集插件。我只是使用单独的配置文件来处理限制(“只能将一个插件添加到核心模块”)。
如果您需要更具体的指导,请添加具体问题:)
If you are just expecting a confirmation, then I confirm that the situation you have described is a perfect use case for the Maven Assembly plugin. I'd just use separate profiles to deal with the restriction ("Only one plugin can be added to the core module").
If you are expecting more specific guidance, please add a specific question :)