gpt4 book ai didi

spring - 使用 Spring Boot 的 starter web parent 时出现 Invalid packaging 错误

转载 作者:行者123 更新时间:2023-12-02 12:32:52 24 4
gpt4 key购买 nike

我想为我的项目使用 spring-boot-starter-web 父级。不幸的是,如果我尝试使用它,我会收到以下错误消息:

[ERROR] [ERROR] Some problems were encountered while processing the POMs:[ERROR] Invalid packaging for parent POM org.springframework.boot:spring-boot-starter-web:2.0.5.RELEASE, must be "pom" but is "jar" @ org.springframework.boot:spring-boot-starter-web:2.0.5.RELEASE @ [ERROR] The build could not read 1 project -> [Help 1][ERROR]   [ERROR]   The project com.company:my-artifact:1.0-SNAPSHOT (/home/user/Projects/my-artifact/pom.xml) has 1 error[ERROR]     Invalid packaging for parent POM org.springframework.boot:spring-boot-starter-web:2.0.5.RELEASE, must be "pom" but is "jar" @ org.springframework.boot:spring-boot-starter-web:2.0.5.RELEASE

If I change the parent to be spring-boot-starter-parent this error does not happen and the build completes without error.

This is a MWE of my 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company</groupId>
<artifactId>my-artifact</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.5.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.version>1.2.71</kotlin.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<configuration>
<jvmTarget>1.8</jvmTarget>
</configuration>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>

该项目是一个使用 IntelliJ 创建的 Kotlin 项目,通过从原型(prototype)创建一个新的 Maven 项目并为 JVM 原型(prototype)选择 kotlin,所以我仅有的文件是 pom.xmlsrc/main/kotlin/com/company/Hello.kt 包含以下内容:

package com.company

fun main(args: Array<String>) {
println("Hello, World")
}

以及src/test/kotlin/com/company/HelloTest.kt下的测试文件:

package com.copmany

import org.junit.Test
import kotlin.test.assertEquals

class HelloTest {

}

据我所知,我的 POM 是正确的。我多次尝试 mvn clean build 但它似乎不是下载的依赖项的问题。 spring-boot-starter-web 不应该用作父级吗?

最佳答案

你必须将spring-boot-starter-parent设置为parent

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

spring-boot-starter-web作为你的依赖

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

<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>

关于spring - 使用 Spring Boot 的 starter web parent 时出现 Invalid packaging 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52643716/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com