Maven中项目间的依赖关系 [英] Inter Project Dependencies in Maven

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

问题描述

我有两个Maven项目: 项目API project-impl

I have two maven projects: project-api project-impl

project-impl的POM指定了对project-api的依赖.顶级聚合pom列出了模块project-api和project-impl.

project-impl's POM specifies a dependency on project-api. The top level aggregation pom lists modules project-api and project-impl.

如果我在顶层运行编译,则依赖关系可以正确解析.如果我在project-impl上运行编译,则找不到依赖项project-api.我如何设置maven,以便当project-impl进行编译时,它首先进行编译并收集其对其他项目的依赖关系?

If I run compile at top level, the dependencies resolves correctly. If I run compile at project-impl, then it can't find dependency project-api. How can I set up maven such that when project-impl compiles, it first compiles and collects its dependencies on other projects?

推荐答案

您只能在根项目中执行此操作

you can only do that from the root project

mvn -pl child -am 

这将构建您的子项目以及所有依赖项在同一棵树中.通常,当您有一个多模块项目时,应该始终从父级而不是从子级进行构建.如果只想构建一个或两个子项目,请执行以下操作:

this will build your sub project and also all dependencies in the same tree. in general, when you have a multi module project, you should always build from the parent, never from the child. And if you only want to build one or two child projects, do this:

mvn -pl child

OR

mvn -pl child2,child3

(已构建项目child2和child3,但未构建项目child1和child4)

(projects child2 and child3 are build, but child1 and child4 aren't)

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

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