使用maven构建webapp及其独立插件

发布于 2024-12-05 03:48:06 字数 1070 浏览 4 评论 0原文

我有一个 Web 应用程序,我将其称为 core,它可以添加插件(不是 Maven 插件),但它应该作为独立的 Web 应用程序运行和构建良好。我们有一个核心依赖的插件库,所有开发到核心的插件也依赖它。

像这样:

core    -> core-plugin-lib
plugins -> core-plugin-lib

我的目录结构很简单:

root/
    core/
        pom.xml
    core-plugin-lib/
        pom.xml
    pluginA/
        pom.xml
    pluginB/
        pom.xml

我的第一个问题是:我可以构建核心或任何插件并构建依赖库吗?我读过有关模块的内容,但正如您所看到的,该库有 2 个父级。我真正想要的是构建核心并构建库,或者如果我构建任何插件,我也想独立构建库。还要注意,核心不依赖于任何插件。

第二个问题是:如何构建核心并构建插件,尽管核心不依赖于它们,并且插件不应该是核心的模块。他们可以,这不是必需的,但我宁愿不这样做,因为我想尽可能保持独立。

截至目前,当我构建插件时,它将自身复制到核心内的 /plugin 目录,并且我在核心 pom 中有一个分发配置文件,用于将现有插件从该目录复制到 web 应用程序的 war 内。因此,当我构建没有配置文件的核心时,它不会复制其插件,但当我运行分发配置文件时,是的。这可行,但很乏味,因为我必须构建库、构建插件并构建核心。

我想知道是否有任何pom结构可以解决我的第一个问题的双重依赖,以及是否有任何方法可以处理第二个问题并通过核心构建插件,即使它们不依赖。并且,如果可能的话,我是否可以在配置文件中而不是单独的 pom.xml 中处理第二个问题。此配置文件使用 maven-assemble-plugin 创建 tar .gz,其中包含所有内容。如果可能的话,我也想保持这一点。

I have a webapp, that I will call core, that can have plugins (not maven plugins) added to it, but it should run and build fine as a stand alone webapp. We have a plugin-lib that the core depends on and that all plugins developed to the core also depends on.

Like this:

core    -> core-plugin-lib
plugins -> core-plugin-lib

My directory structure is simple:

root/
    core/
        pom.xml
    core-plugin-lib/
        pom.xml
    pluginA/
        pom.xml
    pluginB/
        pom.xml

My first problem is: can I build the core or any plugin and also build the dependent lib? I read about modules, but as you can see, the lib has 2 parents. What I would really want is to build core and also build the lib OR if I built any plugin, I would also like to build the lib independently. And mind also, that the core does not depend on any plugin.

The second problem is: how to build the core and also build the plugins, although the core does not depend on them, and the plugins should not be a module of the core. They could, it is not a requisite, but I'd rather not as I'd like to maintain as independent as possible.

As of now, when I build the plugin, it copies itself to a /plugin directory inside the core, and I have a distribution profile in the core pom to copy the existing plugins from this directory to inside the war of the webapp. So when I build the core with no profile, it does not copy its plugins, but when I run the distribution profile, yes. This works but it is tedious, as I have to build the lib, build the plugins and build core.

I would like to know if there is any pom structure that could solve the double dependency of my first problem, and if there is any way to handle the second problem and build the plugins through the core even though they are not dependent. And, if possible, if I could handle the second problem within a profile instead of a separate pom. This profile uses the maven-assembly-plugin to create a tar.gz with everything packed in it. I would also like to maintain that if possible.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

×纯※雪 2024-12-12 03:48:06

我阅读了有关模块的内容,但正如您所看到的,该库有 2 个父级。

我认为您的意思是该库有 2 个依赖于它的项目。父项在 Maven 中意味着特定的东西:由另一个 POM 继承的 POM。在这种情况下,我认为模块就是您正在寻找的。

至于您是否可以使用核心和插件构建库,那么是的,这是可能的。这是个好主意吗?我会说,不。插件库定义了插件和核心之间的契约。一般来说,您想确切知道您所依赖的版本,并且不一定始终是最新的。我建议您保持库的版本独立于其他项目,并根据需要构建它。然后让您的核心和插件取决于您所针对的本地(或远程)存储库中的版本。

如果您决定将它们构建在一起,那么只需定义一个单独的多模块 POM(可能位于其他 POM 旁边),其中将两个项目作为模块包含在内。

关于第二个问题,您当然可以定义一个单独的 POM,将核心和插件构建在一起。使用相同的多模块技术。

I read about modules, but as you can see, the lib has 2 parents.

I think you mean that the lib has 2 projects that depend on it. A parent means something specific in Maven: A POM that is inherited by another. In this case, I think modules are what you are looking for.

As to whether you can build the lib with the core and the plugins, then yes, it's possible. Is it a good idea? I would say, no. The plugin lib defines a contract between the plugins and the core. Generally you want to know exactly which version you are depending on, and not necessarily the latest all the time. I would recommend you keep the version of the lib independent of the other projects, and build it as necessary. Then let your core and plugins depend on the version in the local (or remote) repository that you are targeting.

If you're determined to build them together, then simply define a separate, multi-module POM, perhaps next to the others, that includes both projects as modules.

Regarding the second question, you can certainly define a separate POM that builds both the core and the plugins together. Use the same multi-module technique.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文