java - 如何告诉 Maven 在本地哪里搜索父 POM?

标签 java maven

我有许多 Maven 项目 在我的机器上 checkout ,格式如下:

my-project/
  pom.xml
my-other-project/
  pom.xml

my-other-project声明 my-project 中的 POM 文件将被用作 parent 。问题是 my-project还不在 Maven 存储库中,这是两个独立的项目,因此 Maven 无法在本地搜索找到父 POM。有没有办法告诉 Maven 查看 my-project/在搜索存储库之前查找父 POM?

这是我在运行 mvn package 时遇到的确切错误:

[INFO] Scanning for projects...
Downloading: https://repo.maven.apache.org/maven2/com/mycom/my-project/1.0.0/pom-base-1.0.0.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.mycom:my-other-project:1.0.0: Could not find artifact com.mycom:pom-base:pom:1.0.0 in central (https://repo.maven.apache.org/maven2) and 'parent.relativePath' points at wrong local POM @ line 39, column 11

编辑:

可以设置<relativePath>../my-project</relativePath在父声明中,但如果这可以自动发生就好了。

最佳答案

relativePath 如果您不想在 repo 中包含本地项目,则可以使用此方法。这就是此元素的用途,如 reference documentation 中所述:

The relative path of the parent pom.xml file within the check out. If not specified, it defaults to ../pom.xml. Maven looks for the parent POM first in this location on the filesystem, then the local repository, and lastly in the remote repo. relativePath allows you to select a different location, for example when your structure is flat, or deeper without an intermediate parent POM. However, the group ID, artifact ID and version are still required, and must match the file in the location given or it will revert to the repository for the POM. This feature is only for enhancing the development in a local checkout of that project. Set the value to an empty string in case you want to disable the feature and always resolve the parent POM from the repositories.

关于java - 如何告诉 Maven 在本地哪里搜索父 POM?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30693312/

相关文章:

java - 如何通过单击按钮选中所有复选框

java - 不使用数组获取 N 个输入的最大值

java - Linux screen 命令执行不起作用?

java - 向 Android 应用程序添加依赖项后出错

Maven GlassFish 插件 : asadmin CreateProcess error=193

java - 多模块maven VS 微服务架构

java - Maven:在不扩展依赖项的情况下使用 flatten 解析版本

java - DB2 Java 用户定义函数

java - 使用 UnmanagedExports 和 JNA 将字节数组从 C# 返回到 Java

resources - 关于 Maven 资源