【问题标题】:Why Maven throws error like `must be "pom" but is "jar"`?为什么 Maven 会抛出类似“必须是“pom”但是是“jar”的错误?
【发布时间】:2020-04-04 19:51:12
【问题描述】:

我需要修复以下 maven 错误。

当我跑步时:

mvn 全新安装

我明白了:

[ERROR] The build could not read 1 project -> [Help 1]
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[ERROR] Invalid packaging for parent POM org.springframework.boot:spring-boot-starter-parent:2.0.5.RELEASE, must be "pom" but is "jar" @ org.springframework.boot:spring-boot-starter-parent:2.0.5.RELEASE
[ERROR] 'packaging' with value 'jar' is invalid. Aggregator projects require 'pom' as packaging. @ line 3, column 102

这是我的包层次结构:

.
├── pom.xml
|
└── application
    └── pom.xml

下面是我在根目录下的 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.tim.project</groupId>
    <artifactId>myservice</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>${project.artifactId}-${project.version}</name>
    <description>My Service</description>
    <packaging>pom</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
        <relativePath/>
    </parent>

    <modules>
        <module>application</module>
    </modules>

</project>

以下是我在应用程序文件夹中的 pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.tom.project</groupId>
    <artifactId>myservice-application</artifactId>
    <version>0.0.2</version>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <repositories>
        <repository>
          ...
        </repository>
    </repositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-sleuth</artifactId>
                <version>2.0.0.RC1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
          <scope>compile</scope>
      </dependency>
      ....
      ....

    </dependencies>

</project>

【问题讨论】:

  • mvn -f application_pom_file.xml clean install 会有帮助吗?

标签: java maven


【解决方案1】:

应用程序文件夹中的 pom.xml 丢失:

<parent>
    <groupId>com.tim.project</groupId>
    <artifactId>myservice</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

【讨论】:

    【解决方案2】:
    <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.0.5.RELEASE</version>
            <relativePath/>
        </parent>
    

    尝试删除 &lt;relativePath/&gt; 并将其替换为 &lt;type&gt;pom&lt;/type&gt;

    编辑

    我有一些非常相似的东西: 根pom

    <groupId>org.company</groupId>
        <artifactId>my-parent</artifactId>
        <version>1.1</version>
        <packaging>pom</packaging>
    
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.8.RELEASE</version>
        </parent>
    

    然后是应用程序:

    <artifactId>my-spring-app</artifactId>
        <packaging>jar</packaging>
    
        <parent>
            <groupId>org.company</groupId>
            <artifactId>my-parent</artifactId>
            <version>1.1</version><!-- version can be different of course-->
        </parent>
    

    【讨论】:

    • 此处不允许元素类型。
    • 然后删除 relativePath
    • 无论如何你为什么不在你的应用程序 pom 中指定父级?我的意思是没有提到上层 pom(根中的那个)
    猜你喜欢
    • 2020-10-15
    • 2021-02-13
    • 1970-01-01
    • 2018-04-09
    • 2020-01-20
    • 1970-01-01
    • 2010-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多