maven - jenkins - 无法解析的父 POM 无法找到 Artifact , 'parent.relativePath' 指向错误的本地 POM

标签 maven build jenkins pom.xml

我遇到了有关 Jenkins 构建的问题。正如标题所描述的,这是一个“无法解析的父 POM 无法找到 Artifact ,并且'parent.relativePath'指向错误的本地 POM” 问题,经常在 stackoverflow 上发现,但我还没有找到一个匹配的。这是我的问题描述

我的项目结构如下所示:

/root-project
 +-----------/pom.xml
/root-project/modul-a/
 +-------------------/pom.xml
/root-project/modul-b/
 +-------------------/pom.xml
/root-project/modul-c/
 +-------------------/pom.xml

在我的本地计算机(Windows)上,我可以使用以下方式构建我的项目:

mvn -f root-project/pom.xml clean install

即使存储库为空,也没有错误。

但是 jenkins (linux) 无法做到这一点。

Gestartet durch Benutzer anonymous
Building in workspace /opt/jenkins/jobs/Project/workspace
Checkout:workspace / /opt/jenkins/jobs/Project/workspace - hudson.remoting.LocalChannel@33333ab9
Using strategy: Default
Last Built Revision: Revision acb4c7d9efd81c1c7d5bbd2f6e190d1cb0a5e359 (origin/HEAD, origin/master)
Fetching changes from 1 remote Git repository
Fetching upstream changes from http://repository.git
Seen branch in repository origin/HEAD
Seen branch in repository origin/master
Seen branch in repository origin/version_branch
Commencing build of Revision acb4c7d9efd81c1c7d5bbd2f6e190d1cb0a5e359 (origin/HEAD, origin/master)
Checking out Revision acb4c7d9efd81c1c7d5bbd2f6e190d1cb0a5e359 (origin/HEAD, origin/master)
Warning : There are multiple branch changesets here
[workspace] $ /opt/apache-maven-3.0.4/bin/mvn -f root-project/pom.xml -e clean install javadoc:aggregate
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[ERROR] The build could not read 8 projects -> [Help 1]
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM: Could not find artifact org.example:rootartifact:pom:1.3.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 3, column 10
[FATAL] Non-resolvable parent POM: Could not find artifact org.example:rootartifact:pom:1.3.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 5, column 11
//...
at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:363)
at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:636)
at org.apache.maven.DefaultMaven.getProjectsForMavenReactor(DefaultMaven.java:585)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:234)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
[ERROR]   
[ERROR]   The project org.example:module-a:1.3.0-SNAPSHOT (/opt/jenkins/jobs/Project/workspace/root-project/module-a/pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM: Could not find artifact org.example:root-project:pom:1.3.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 3, column 10 -> [Help 2]
org.apache.maven.model.resolution.UnresolvableModelException: Could not find artifact org.example:root-project:pom:1.3.0-SNAPSHOT

这就是我的父 pom 中的内容

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>root-project</artifactId>
<version>1.3.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
    <module>module-a</module>
    <module>module-b</module>

以及模块 pom 的示例

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>root-project</artifactId>
    <groupId>org.example</groupId>
    <version>1.3.0-SNAPSHOT</version>
  </parent>
  <artifactId>module-a</artifactId>
  <dependencies>
     //..
  </dependencies>
</project>

正如我尝试过的其他条目中提到的,但它并没有改变结果。为什么要这么做呢,它指向的是父级从未去过的存储库。 那么有人建议我做错了什么吗?

按照要求,这是 mvn help: effective-pom 的输出:

[INFO] Scanning for projects...
[ERROR] The build could not read 3 projects -> [Help 1]
[ERROR]   
[ERROR]   The project org.example:modul-a:1.3.0-SNAPSHOT (/tmp/project/project-root/modul-a/pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM: Could not find artifact org.example:project:pom:1.3.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 3, column 10 -> [Help 2]
[ERROR]   
[ERROR]   The project org.example:modul-b:1.3.0-SNAPSHOT (/tmp/project/project-root/modul-b/pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM: Could not find artifact org.example:project:pom:1.3.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 5, column 11 -> [Help 2]
[ERROR]   
[ERROR]   The project org.example:modul-c:1.3.0-SNAPSHOT (/tmp/project/project-root/modul-c/pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM: Could not find artifact org.example:project:pom:1.3.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 6, column 10 -> [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

最佳答案

<artifactId>对于您的示例模块 pom 中的父级,是 root-project .

<artifactId>在你的父 pom 中是 prject 。在 jenkins 输出中, Artifact 的名称似乎被解析为 rootproject 。尝试设置父级的 pom <artifactId> root-project (注意额外的“-”)。

我不确定这是如何在你的机器上构建的。您可以发布运行 mvn help:effective-pom 的输出吗?在你的机器和运行 jenkins 的机器上?

无论如何,您可以启用 -X调试输出的标志,以查看 Maven 可能尝试采取的操作。我发现这在调试 Maven 项目的配置时很有用。

关于maven - jenkins - 无法解析的父 POM 无法找到 Artifact , 'parent.relativePath' 指向错误的本地 POM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14797263/

相关文章:

go - 通过 jenkins 部署 go 应用程序

linux - headless Protractor 测试不插入 Xvfb

java - 如何为 maven-changes-plugin 配置超时?

java - Maven 和 native 库文件

C# 抑制 MS Fakes 警告

java - 仅导入使用 maven 构建的库的一个配置文件

java - Maven pom.xml - 构建模块+自构建

java - Mule 编译失败,maven : Invalid content was found starting with element 'db:generic-config'

c++ - 在 Visual Studio 中发布版本仍然更慢?

jenkins - JobDSL - 如果 Jenkins 中尚不存在则创建一个新作业