spring - 使用 Spring Boot 的 starter web parent 时出现无效的打包错误
问题描述
我想spring-boot-starter-web
为我的项目使用父级。不幸的是,如果我尝试使用它,我会收到以下错误消息:
[ERROR] [ERROR] 处理 POM 时遇到了一些问题: [错误]父 POM org.springframework.boot:spring-boot-starter-web:2.0.5.RELEASE 的包装无效,必须是“pom”但是“jar”@org.springframework.boot:spring-boot-starter -web:2.0.5.RELEASE @ [错误] 构建无法读取 1 个项目 -> [帮助 1] [错误] [错误] 项目 com.company:my-artifact:1.0-SNAPSHOT (/home/user/Projects/my-artifact/pom.xml) 有 1 个错误 [错误] 父 POM org.springframework.boot:spring-boot-starter-web:2.0.5.RELEASE 的包装无效,必须是“pom”但是“jar”@org.springframework.boot:spring-boot-starter -web:2.0.5.RELEASE
如果我将其更改为parent
不会spring-boot-starter-parent
发生此错误,并且构建完成且没有错误。
这是我的 MWE 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 项目,通过从原型创建一个新的 Maven 项目并为 JVM 原型选择 kotlin,因此我拥有的唯一文件是pom.xml
以下src/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>
<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>
推荐阅读
- javascript - 如何在不转到新主页的情况下更改网站布局
- c# - 计算c#列表中元素的实例
- rust - 从 Rust 为机器类型 wasm32 构建 LLVM
- tvos - 无法通过 Apple Configurator 2 在 Apple TV 上安装 Charles Proxy 配置文件
- c++ - 通过 F() makro 打印字符数组
- azure - 为本地环境设置 Azure Application Insights
- python - 使用 plt.savfig 在 Google Colab 上使用轴保存图形
- python-3.x - 在 Solaris 服务器上安装 Python3 的步骤
- sql - 是否有任何规则或文档可用于 Oracle 数据库选择语句的列名的输出名称?
- javascript - 当元素根本没有出现在页面上时检查元素的可见性