Gia*_*tta 3 spring maven kotlin spring-boot
我想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>
Run Code Online (Sandbox Code Playgroud)
该项目是通过建立从原型一个新的Maven项目,所以我唯一的文件选择适合JVM原型的科特林用的IntelliJ创造了科特林项目pom.xml
和src/main/kotlin/com/company/Hello.kt
具有以下内容:
package com.company
fun main(args: Array<String>) {
println("Hello, World")
}
Run Code Online (Sandbox Code Playgroud)
和下的测试文件src/test/kotlin/com/company/HelloTest.kt
:
package com.copmany
import org.junit.Test
import kotlin.test.assertEquals
class HelloTest {
}
Run Code Online (Sandbox Code Playgroud)
据我所知,我的 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>
Run Code Online (Sandbox Code Playgroud)
并 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>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1552 次 |
最近记录: |