本文介绍了Maven父项目自动化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个结构

          **** child C


父母(A)


Parent (A)

          **** child B

如果我尝试在没有父级的情况下安装子级B,那么maven会抛出一个错误,按照惯例,我知道应该在存储库中安装了父级B,但是有人可以在安装过程中拉动该子级吗? ,自动安装父级?

If I try to install child B without the parent, maven throws me an error, I know by convention I should have the parent installed in my repository, but is there any way for someone to pull the child and during the install process, install the Parent automatically?

@edit我将尝试变得更加清晰,我有一个依赖于项目A的项目B(项目A是父项目,与项目B中的项目相同),我希望能够在项目B中进行构建而无需在项目B中存在A我想以某种方式从B的本地"(m2>存储库)存储库中安装A,这样,要对B进行操作的开发人员就不必手动安装A

@editI'm going to try to be clearer, I have a project B that depends on project A (Project A is parent, same as in project B) I would like to be able to build in project B without needing the existence of A in my ' Local '(m2> repository) Repository, I would like some way, from B also install A, so that a developer who will act on B does not have to manually install A before

推荐答案

长话短说:不.(至少不是直接.)

Long story short: No. (Not directly, at least.)

您不能运行另一个项目的构建(但是要运行 aggregator/多模块项目或使用 Maven Invoker插件或Groovy或Ant脚本之类的东西.但是在您要执行后者的情况下,依赖关系解析应该已经完成​​,并且会失败.)

You can't run a build of a project from another one (but from an aggregator/multi-module project or with the Maven Invoker Plugin or a Groovy or Ant script or the like. But at the time you'd perform one of the latter in your case the dependency resolution would have been done already, and would have failed.)

您可以采用另一种方式来做到这一点,例如:

You can do it the other way round like:

+- aggregator
   +- pom.xml: <packaging>pom, <module>parent (A), <module>child B
   |
   +- parent (A)
   |  +- pom.xml
   |
   +- child B
   |  +- pom.xml: <parent>parent (A), <relativePath>../parent (A), <dependency>parent (A)
   |
   +- child C
      +- pom.xml: <parent>parent (A), <relativePath>../parent (A)

构建aggregator按此顺序构建parent (A)child B,因为Maven Reactor可以识别child Bparent (A)的依赖性.

Building aggregator builds parent (A) and child B in that order since the Maven Reactor recognizes the dependency of child B on parent (A).

这篇关于Maven父项目自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 15:49