添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

springboot父bom与子pom打包,报错'parent.relativePath' points at no local POM

1.报错信息

+ echo 开始编译构建
开始编译构建
+ mvn clean package -Dmaven.test.skip=true
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.cxf:cxf-zuul:0.0.1-SNAPSHOT: Could not find artifact com.cxf:cxf-tools:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at no local POM @ line 5, column 13
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project com.cxf:cxf-zuul:0.0.1-SNAPSHOT (/root/.jenkins/workspace/springboot/cxf-zuul/pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM for com.cxf:cxf-zuul:0.0.1-SNAPSHOT: Could not find artifact com.cxf:cxf-tools:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at no local POM @ line 5, column 13 -> [Help 2]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
Build step 'Execute shell' marked build as failure
Finished: FAILURE

原因在于在pom中配置<parent>时,需指定<relativePath>.

相对路径的默认值是../pom.xml. <relativePath/>设定一个空值将始终从仓库中获取,不从本地路径获取。

maven首先会在当前路径下寻找父项目pom.xml,其次会在relativePath下寻找,然后在本地仓库,最后在远程仓库中寻找。

官方建议:

This error is raised when your POM inherits from a parent POM or imports another POM that Maven could not download. Possible causes for this error are:

  1. You are referring to a non-existing POM, e.g. by means of a typo in its group id, artifact id or version.
  2. You intent to use a parent POM from the local filesystem but Maven didn't use that. Please verify that the <relativePath> element in the child is properly set and that the POM at that location has actually the version you want to use.
  3. Your POM/settings is missing the required <repository> to download the POM. Note that <pluginRepository> declarations are not considered when looking for the POM, only <repositories> are searched for POMs.
  4. The repository you have configured requires authentication and Maven failed to provide the correct credentials to the server. In this case, make sure your ${user.home}/.m2/settings.xml contains a <server> declaration whose <id> matches the <id> of the remote repository to use. See the Maven Settings Reference for more details.
  5. Maven failed to save the files to your local repository, see LocalRepositoryNotAccessibleException for more details.
  6. The repository you have configured is disabled for the specific version of the POM you requested. For instance, if you want to use a SNAPSHOT version of a POM, make sure you don't have <snapshots><enabled>false</enabled></snapshots> configured. Likewise, in order to resolve a released version of the POM, the remote repository should not be configured with <releases><enabled>false</enabled></releases> . See the POM Reference for more information on repository configuration.

In those cases, check your POM and/or settings for the proper contents. If you configured the repository in a profile of your settings.xml , also verify that this profile gets actually activated, e.g. via invoking mvn help:active-profiles .

For the special case of a network-related problem during download of the POM, you can also consult the following articles:

2.解决方式(三种)

父pom

<groupId>com.cxf</groupId>
<artifactId>cxf-tools</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>cxf-tools</name>
<description>Demo project for Spring Boot</description>
<packaging>pom</packaging>

子pom依赖

mvn打包时报错
<parent>
    <groupId>com.cxf</groupId>
    <artifactId>cxf-tools</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<artifactId>cxf-zuul</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>cxf-zuul</name>
<description>cxf-zuul</description>
<packaging>jar</packaging>
----修改方式一 删除 <relativePath/>
<parent>
    <groupId>com.cxf</groupId>
    <artifactId>cxf-tools</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>cxf-zuul</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>cxf-zuul</name>
<description>cxf-zuul</description>
<packaging>jar</packaging>
----修改方式二指向父pom位置
<parent>
    <groupId>com.cxf</groupId>
    <artifactId>cxf-tools</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
<artifactId>cxf-zuul</artifactId>
<version>0.0.1-SNAPSHOT</version>