Maven:捆绑特定的依赖项 [英] Maven: bundle specific dependency

查看:48
本文介绍了Maven:捆绑特定的依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下,您有特定于环境的构建,结果分为两个包:家庭和办公室.您构建的特定于环境的工件取决于一些常见的工件,我们称之为核心".它只是家庭和办公版本的常见功能.Home神器依赖Core,Office神器依赖Core.事实上,家庭和办公室甚至可以是相同的工件,它只是在不同的 Maven 配置文件下构建:如果我们使用 -pHomeBundle 调用 Maven,它会以一种方式构建工件,如果使用 -pOfficeBundle - 它为办公室构建它,两次都需要Core 作为依赖项,与 Home 相同.

Imagine you have environment-specific build which results into two bundles: Home and Office. Environment-specific artifact of your build depends on some common artifact, lets call it 'Core'. It is just a common functionality for Home and Office builds. Home artifact depends on Core, and Office artifact depends on Core. In fact, Home and Office can even be the same artifact which is just build under different Maven profiles: in case we call Maven with -pHomeBundle it builds artifact one way, in case with -pOfficeBundle - it builds it for office, both times taking Core as a dependency which is the same as for Home.

到目前为止一切顺利.

现在的问题是:如果家庭和办公包常见的核心工件依赖于家庭和办公包不同的其他工件,我们该怎么办?IE.核心工件不依赖于包,但它的依赖是.

Now a question is: what can we do if Core artifact, which is common for Home and Office bundles has dependencies on other artifacts which are DIFFERENT for Home and Office bundles? I.e. Core artifact is not bundle-dependent, but its dependencies are.

我们如何为我们的 Core 提供这种依赖?

How can we provide our Core with this dependencies?

我们如何为此编写 Core POM?

How can we write Core POM for this?

更新针对这个问题提出了两种解决方案:按照提供的方式向Core项目添加两个特定于bundle的依赖项(然后在以Core为依赖项的特定于bundle的模块Home/Office中添加一个real),或者向Core模块添加两个real依赖然后在特定于捆绑包的模块 Home/Office 中过滤它们.但是我无法确定将构建哪个依赖项 Core.无论我们是否提供它 - 它都应该带有一些依赖项,因为它会进入存储库.据我所知,它只会选择第一个可用的类并使用它.因此,我将使用其中一个依赖项构建一个 Core 工件.

UPDATE Two solutions were suggested for this problem: add two bundle-specific dependencies to Core project as provided (and then add one real in the bundle-specific module Home/Office which takes Core as a dependency), or add two real dependencies to Core module and then filter them in the bundle-specific module Home/Office. But I cannot get with which dependency Core will be build. No matter we provide it or not - it should be build with some dependency because it goes to repository. As far as I understand it will just take the first available class and use it. So I will have a Core artifact built using one of the dependencies.

推荐答案

我更愿意将那些特定于捆绑包的依赖项添加到它们各自的 pom.xml 中,并将它们排除在核心依赖项下,以便我 100% 确定只得到为该项目添加的那些依赖库.

I would prefer to have those bundle specific dependencies added in their respective pom.xml and exclude them under the core dependencies so that I am 100% sure of getting only those dependent libraries added for that project.

当我们不得不为两个不同的运行时构建相同的应用程序时,我们在我们的应用程序中遇到了类似的情况,并且一些框架库将运行时库捆绑在其中.因此,我们最终将它们从核心依赖项中排除,并将它们作为单独的依赖项包含在应用程序 POM 中.

We have encountered a similar situation in our application when we had to build the same application for two different runtimes and some framework libraries had the runtime libraries bundled in them. So we ended up excluding them from the core dependency and included them as individual dependencies to the application POM.

希望这是有道理的,也有帮助.很想知道传说是否有更好的方法.

Hope this makes sense and also helps. Curious to learn if legends have a better approach.

这篇关于Maven:捆绑特定的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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