Spring Initializr生成的pom.xml错误

时间:2018-11-16 15:59:48

标签: spring maven spring-boot kotlin pom.xml

我正在使用Spring Tool Suite,并且我想使用Kotlin,Spring和Maven创建REST API,但是通过Spring Initializr创建项目后,我的pom.xml出现错误。我的“父”标签引发了一个错误,但我猜问题出在kotlin-maven-plugin。我不知道这个pom.xml怎么了。如果有人可以帮助我解决此问题,我将不胜感激!

这是我的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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>fr.asi</groupId>
<artifactId>api_kotlin_test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>api_kotlin_test</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.6.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <kotlin.version>1.2.51</kotlin.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-cache</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.module</groupId>
        <artifactId>jackson-module-kotlin</artifactId>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-stdlib-jdk8</artifactId>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-reflect</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
    <testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <artifactId>kotlin-maven-plugin</artifactId>
            <groupId>org.jetbrains.kotlin</groupId>
            <configuration>
                <args>
                    <arg>-Xjsr305=strict</arg>
                </args>
                <compilerPlugins>
                    <plugin>spring</plugin>
                    <plugin>jpa</plugin>
                </compilerPlugins>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.jetbrains.kotlin</groupId>
                    <artifactId>kotlin-maven-allopen</artifactId>
                    <version>${kotlin.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.jetbrains.kotlin</groupId>
                    <artifactId>kotlin-maven-noarg</artifactId>
                    <version>${kotlin.version}</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

我有这个错误:

Project configurator "org.jetbrains.kotlin.maven.projectConfigurator" required by plugin execution "org.jetbrains.kotlin:kotlin-maven-plugin:1.2.51:test-compile (execution: test-compile, phase: test-compile)" is not available. To enable full functionality, install the project configurator and run Maven->Update Project Configuration.

2 个答案:

答案 0 :(得分:2)

我在pom.xml中添加一个属性,如下所示:

<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>

添加此属性后,只需保存pom.xml并更新您的项目。该错误应得到解决。 以下是pom.xml的摘录:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.8.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.in28minutes.learning.jpa</groupId>
    <artifactId>jpa-in-10-steps</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>jpa-in-10-steps</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
    </properties>

答案 1 :(得分:0)

我通过添加“ plugingManagement”标签来封装“ plugins”标签来消除该错误,如下所示:

<pluginManagement>
    <plugins>
     .......
    </plugins>
</pluginManagement>

注意:此更改只是消除了错误,但我仍然无法运行代码(在我的情况下,Eclipse中的“以Kotlin应用程序运行”选项不存在。)我不确定这些错误是否有关系,但我不能确定它们不是。

编辑:我只是通过将IDE切换到IntelliJ IDEA来避免此问题,看来Eclipse的Kotlin插件目前尚不完善...现在一切都很好,“ pluginManagement”标记没有用现在。