Maven 子项目 - 不可解析的父 POM

Posted

技术标签:

【中文标题】Maven 子项目 - 不可解析的父 POM【英文标题】:Maven Child Project- Non-resolvable parent POM 【发布时间】:2021-11-16 11:18:02 【问题描述】:

我正在尝试将一个子项目变成一个父项目(这个子项目真的不依赖于父项目,所以我试图把它变成一个父项目,这样我就可以在 jenkins 文件中将它与另一个项目合并) .

我更改了 POM 文件的父部分

<parent>
   <artifactId>org.springframework.boot</artifactId>
    <groupId>spring-boot-starter-parent</groupId>
    <version>1.2.5.RELEASE</version>
</parent>

但是当我构建时,我在 jenkins 中收到以下错误。

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/usr/share/maven/lib/guice.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[[1;34mINFO[m] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/spring-boot-starter-parent/org.springframework.boot/1.2.5%20RELEASE/org.springframework.boot-1.2.5%20RELEASE.pom
[[1;31mERROR[m] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for demo-api:demo-api:1.0-SNAPSHOT: Could not find artifact spring-boot-starter-parent:org.springframework.boot:pom:1.2.5 RELEASE in central (https://repo.maven.apache.org/maven2) and 'parent.relativePath' points at wrong local POM @ line 5, column 13
 @ 
[[1;31mERROR[m] The build could not read 1 project -> [1m[Help 1][m
[[1;31mERROR[m]   
[[1;31mERROR[m]   The project demo-api:demo-api:1.0-SNAPSHOT (/home/estt/jenkins/workspace/demo-api-2/pom.xml) has 1 error
[[1;31mERROR[m]     Non-resolvable parent POM for demo-api:demo-api:1.0-SNAPSHOT: Could not find artifact spring-boot-starter-parent:org.springframework.boot:pom:1.2.5 RELEASE in central (https://repo.maven.apache.org/maven2) and 'parent.relativePath' points at wrong local POM @ line 5, column 13 -> [1m[Help 2][m
[[1;31mERROR[m] 
[[1;31mERROR[m] To see the full stack trace of the errors, re-run Maven with the [1m-e[m switch.
[[1;31mERROR[m] Re-run Maven using the [1m-X[m switch to enable full debug logging.
[[1;31mERROR[m] 

这是完整的 pom.xml 文件。

<?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">
    <parent>
       <artifactId>org.springframework.boot</artifactId>
        <groupId>spring-boot-starter-parent</groupId>
        <version>1.2.5.RELEASE</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <packaging>jar</packaging>

    <artifactId>demo-api</artifactId>
    <groupId>demo-api</groupId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
    <dependency>
      <groupId>javax.xml.bind</groupId>
      <artifactId>jaxb-api</artifactId>
      <version>2.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
            <version>2.3.3</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.easymock</groupId>
            <artifactId>easymock</artifactId>
            <version>3.4</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.apiDemo.ApiApplication</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

【问题讨论】:

请检查您的pom.xml1.2.5RELEASE 之间的版本是否有空格,例如1.2.5 RELEASE 而不是1.2.5.RELEASE 我强烈建议使用更新版本的 spring boot,因为 1.X 线的 EoL 时间更长。当前的spring boot版本是2.5.4...spring.io/blog/2021/08/19/spring-boot-2-5-4-available-now 【参考方案1】:

您在父级中的 groupId 和 artifactId 是相反的:

应该是:

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.5.RELEASE</version>
    <relativePath/>
  </parent>

代替

  <parent>
    <groupId>spring-boot-starter-parent</groupId>
    <artifactId>org.springframework.boot</artifactId>
    <version>1.2.5.RELEASE</version>
    <relativePath/>
  </parent>

【讨论】:

以上是关于Maven 子项目 - 不可解析的父 POM的主要内容,如果未能解决你的问题,请参考以下文章

使用 Maven 3.0.3 和 relativePath 表示法的不可解析的父 POM

Eclipse 中不可解析的父 POM

Maven:不可解析的父 POM 和“parent.relativePath”指向错误的本地 POM

Maven:不可解析的父POM和'parent.relativePath'指向错误的本地POM

不可解析的父 POM,尽管 relativePath 设置为现有的父 pom.xml

尝试使用 $parent.groupid 从子 pom 引用父 pom 时出现“不可解析的父 POM:无法传输工件”