两个不同的项目在 Maven 中具有共享的依赖项目
我有两个项目“appA”和“appB”,每个项目都依赖于第三个项目“common”。我正在将它们从 ant 转移到 Maven,但我在找出在 Maven 中执行此操作的最佳方法时遇到了一些困难。我的文件夹结构如下所示:
root
+ common
+ appA
+ appB
我已经能够将父 pom.xml 添加到根目录,并将 common、appA 和 appB 作为此父项目的模块来构建 appA 和 appB,但这不是我想要的,根 pom.xml 是不合适的,因为 appA 和 appB 是完全不相关的项目。
我希望 appA 和 appB 成为单独的 Maven 项目,它们都依赖于第三个公共项目,并在必要时构建它,这样我就可以进入 appA 或 appB 文件夹并输入“mvn package”来构建 appA + common或 appB + common 分别。这就是我在 Ant 中设置它的方式,但在 Maven 中可能没有适当的相似之处。非常感谢任何朝着正确方向的帮助或推动:)
I have two projects, "appA" and "appB", that each depend on a third project, "common". I'm in the process of moving them from ant to maven, but I'm having some difficulty figuring out the best way to do it in maven. My folder structure looks like this:
root
+ common
+ appA
+ appB
I've been able to add a parent pom.xml to the root and have common, appA and appB as modules of this parent project to get appA and appB to build, but this is not what I want, a root pom.xml is not appropriate since appA and appB are completely unrelated projects.
I'd like appA and appB to be separate maven projects which both depend on the third common project and will build it if necessary, so that I can go into either the appA or appB folder and type "mvn package" to build appA + common or appB + common, respectively. This is how I have it set up in Ant but there may not be an appropriate parallel in maven. Any help or nudges in the right direction is greatly appreciated :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那么就不要这样做,如果不想的话就不要使用聚合,只需在
appA
的 POM 和appB
。像这样的事情:依赖关系是通过本地存储库解决的,因此您必须首先
mvn install
common
项目(并在进行任何更改以使它们“可见”之后)。在开发过程中,常见的做法是在 IDE 中导入依赖项目,并将它们配置为依赖于工作空间内的项目(相对于二进制依赖项)。这将节省
安装
步骤以使更改可见。大多数 IDE 都支持这种方法。Then don't do it, don't use aggregation if you don't want to and just declare
common
as a dependency in the POM ofappA
and in the POM ofappB
. Something like this:Dependencies are resolved through the local repository so you'll have to
mvn install
thecommon
project first (and after any change to make them "visible").During development, a common practice is to import dependent projects in your IDE and to configure them to depend on project inside the workspace (vs binary dependencies). This saves the
install
step to make changes visible. Most IDEs support this approach.