【问题标题】:How to solve problem with importing spring application with Maven?如何解决使用 Maven 导入 spring 应用程序的问题?
【发布时间】:2020-01-21 05:34:15
【问题描述】:

我有 java api,我正在尝试使用 Maven 在 Intellij 中导入,这就是我得到的:

无法解析插件 org.springframework.boot:spring-boot-maven-plugin:

这是我的 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>sample</groupId>
<artifactId>sample-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
<description>Parent </description>

<modules>
    <module>sample-repository-mongo</module>
    <module>sample-service</module>
    <module>sample-webservice</module>
</modules>

<prerequisites>
    <maven>3</maven>
</prerequisites>

<properties>
    <framework.version>0.0.0</framework.version>
</properties>

<dependencyManagement>
    <dependencies>
        <!-- Module dependencies -->
        <dependency>
            <groupId>eu.everis.cordis.sample</groupId>
            <artifactId>sample-webservice</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>eu.everis.cordis.sample</groupId>
            <artifactId>sample-service</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>eu.everis.cordis.sample</groupId>
            <artifactId>sample-repository-mongo</artifactId>
            <version>${project.version}</version>
        </dependency>

        <!-- Spring dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.0.3.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- JSON -->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.5</version>
        </dependency>

        <!-- Unit Testing -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>

        <!-- Logging -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.11.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.11.0</version>
        </dependency>
    </dependencies>
</dependencyManagement>


<dependencies>

</dependencies>

<build>
    <!-- <finalName>${warname}</finalName> -->
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.0.0</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
                <outputDirectory>.</outputDirectory>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

到目前为止,我能找到的关于类似问题的唯一线程是this one 我已经尝试过使用最新版本的解决方案,但不幸的是它没有帮助。

我有用于项目结构的 java 8,我也尝试过使用 Maven 3.6.2 和 3.6.1,因为前段时间我能够在另一台笔记本电脑上使用 Maven 3.6.1 导入它。

我已经仔细检查了 java 和 maven 环境变量,我知道它们没问题。我也试过运行mvn clean install, mvn install, mvn package, mvn validate 和我能找到的任何其他命令,但问题仍然存在。

【问题讨论】:

  • 你能试试mvn -U clean install - 强制更新依赖吗?
  • 您显示的 pom 是您的父 pom,对吗?那为什么你有一个 build 部分而不是一个 pluginManagement 部分,就像你的依赖项一样?
  • 而且这个 pom 没有父工件。通常,Spring 引导项目将工件 spring-boot-starter-parent 作为父项,而不是常规依赖项。
  • 我尝试运行mvn -U clean install,但它没有改变,它告诉我一个关于编码的错误并且仍然显示一堆错误。是的。这是 3 个模块的父 pom,我并不真正了解 Maven,我知道我之前导入了这个项目并且它有效,但我现在不知道是什么问题。父 pom 的结构应该不同吗?
  • 你能添加确切的错误信息吗?

标签: spring maven intellij-idea


【解决方案1】:

我的版本 2.3.4 导致我的 IntelliJ IDEA 2019.3.1(终极版)出现问题。将其改回 2.3.2 为我解决了这个问题。现在我有以下配置:

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

【讨论】:

    【解决方案2】:

    这是一个 Spring Boot 项目,所以 pom must have a parent。只需在 pom.xml 的顶部添加这些行:

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

    这个父级将负责依赖的版本。

    【讨论】:

    • 我不得不将版本从 2.1.8 更改为 2.0.3,但它成功了,非常感谢!
    猜你喜欢
    • 2019-06-06
    • 1970-01-01
    • 2020-02-10
    • 2019-07-25
    • 1970-01-01
    • 1970-01-01
    • 2019-07-04
    • 1970-01-01
    • 2014-10-21
    相关资源
    最近更新 更多