Maven抱怨父母的相对路径 [英] Maven complaining about parent relative path

查看:182
本文介绍了Maven抱怨父母的相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一个带有模块的Maven项目,其中包含一些实用程序(jar)和一些poms,供其他人参考(如果他们想使用其中的某些实用程序).

Consider a maven project with modules consists of some utilities (jar) and some poms for others to reference to if they want to use some of these utilities.

例如在父pom.xml中

e.g. inside the parent pom.xml

<artifactId>project-parent</artifactId>
<modules>
  <module>client-ref-pom</module> (a module with just one pom.xml)
  <module>server-ref-pom</module> (a module with just one pom.xml)
  <module>client-utils</module> (a module with some utility classes, needs to ref. client-ref-pom)
  <module>server-utils</module> (a module with some utility classes, needs to ref. server-ref-pom)
  <module>utils</module> (a module with some utility classes, needs to ref. project-parent)
</modules>

因此,如果有另一个项目希望使用utils,它将引用ref-pom作为其父pom,以便可以继承属性.此目的已实现.

So if there is another project wishes to use the utils, it will reference to ref-pom as its parent pom, so that the properties can be inherited. This purpose is served.

当前问题是当模块utils还需要引用ref-pom作为其父pom(而ref-pom将引用project-parent作为其父pom)时,maven抱怨"parent.relativePath"指向转到项目父级而不是ref-pom,建议再次验证项目结构.

The current issue is when the module utils also needs to reference to ref-pom as its parent pom (and ref-pom will ref. project-parent as its parent pom), maven is complaining about 'parent.relativePath' pointing to project-parent instead of ref-pom, suggesting to verify again the project structure.

这只是警告,我仍然可以编译项目,但是我想知道设置项目结构的正确方法,以便使maven满意并达到我的目的.

As that is just a warning, I can still compile the project, but I wonder the proper way to setup the project structure so that maven is happy and my purpose is served.

推荐答案

为了解析父项目,请检查以下可能的来源:

In order to resolve the parent project, these possible sources are checked:

  • relativePath
  • 本地存储库
  • 远程存储库

相对路径(如果未明确给出)默认为..,即当前项目的父目录中的pom.因此,Maven会检查a)该目录中是否有pom文件,以及b)该pom文件是否包含与当前项目的父级定义中所述的坐标相同的坐标.

The relative path, if not given explicitly, defaults to .., i.e. the pom in the parent directory of the current project. So Maven checks whether a) there is a pom file in that directory and b) that pom file contains the same coordinates as stated in the parent definition of the current project.

如果a)和b)为true,则将该pom文件用作解析有效pom的父文件.

If a) and b) are true, that pom file is used as the parent for the resolving of the effective pom.

如果a)为true,b)为false,则会发出警告,因为这通常指向配置错误的项目(如您的情况),并且pom被忽略.

If a) is true, and b) is false, a warning is given, because this usually points to a misconfigured project (as in your case) and the pom is ignored.

如果a)为假,则检查其他来源.

If a) is false, the other sources are checked.

所以,就您而言,我假设您的utils/pom.xml中包含以下内容

So, in your case, I assume you have the following in your utils/pom.xml

<parent>
  <groupId>...</groupId>
  <artifactId>ref-pom</artifactId>
  <version>..</version>
</parent>

隐式包含<relativePath>..</relativePath>.因此,Maven检查utils的父目录,找到一个POM,但这一点被命名为project-parent而不是预期的ref-pom.因此,警告.

which implicitly includes <relativePath>..</relativePath>. So Maven checks the parent directory of utils, finds a POM, but this point is named project-parent instead of the expected ref-pom. Thus the warning.

以下方法将起作用:

<parent>
  <groupId>...</groupId>
  <artifactId>ref-pom</artifactId>
  <version>..</version>
  <relativePath>../ref-pom</relativePath>
</parent>

(请注意,在本文中,您写的是ref-pom,但是在上面的模块中只有client-ref-pomserver-ref-pom)

(Note that in your text, you write about ref-pom, but in the modules above there is only client-ref-pom and server-ref-pom)

但是

在您的情况下,您应该考虑这是否是您真正想要的,如果确实需要单独的*-ref-pom模块,或者这些pom的内容是否可以并且应该更好地放置在相应的*-util模块内部.

You should think about whether this is really what you want, in your case, if the separate *-ref-pom modules are really necessary or if the content of those poms could and should be better placed inside of the respective *-util modules.

这篇关于Maven抱怨父母的相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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