我想在项目中使用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
如果我将parent
更改为spring-boot-starter-parent
,则不会发生此错误,并且构建过程将完成且没有错误。
这是我的pom.xml
的MWE:
<?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
是否应该用作父母?
答案 0 :(得分:2)
您必须将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>
答案 1 :(得分:0)
我建议使用https://docs.spring.io中的“ Spring Boot参考指南”