【问题标题】:Maven - Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.4.1:runMaven - 无法执行目标 org.springframework.boot:spring-boot-maven-plugin:2.4.1:run
【发布时间】:2023-03-17 21:33:01
【问题描述】:

我在https://start.spring.io/创建了我的项目
网上的几个错误类似,但没有解决我的问题。

执行时发现报错:

未能执行目标 org.springframework.boot: spring-boot-maven-plugin: 2.4.1: run

这是我的 POM 和主文件 main

POM:

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>net.javaguides</groupId>
    <artifactId>spring-boot-restfull-webservice</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-boot-restfull-webservice</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </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>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

类:

package net.javaguides.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringBootRestfullWebserviceApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringBootRestfullWebserviceApplication.class, args);
    }
}

我是 Springboot 新手,如何解决?

【问题讨论】:

  • 你是如何运行 maven 的?看起来该项目有一个 maven 包装器,即 zip 中的 mvnw.cmd 您是从提取它的根目录运行 ./mvnw.cmd clean install 还是 unix ./mvnw clean install
  • 是的专家!已经运行了 mvn 命令 clean install qur 也返回一个错误
  • 您是否尝试将&lt;pluginRepositories&gt; &lt;pluginRepository&gt; &lt;id&gt;repository.spring.release&lt;/id&gt; &lt;name&gt;Spring GA Repository&lt;/name&gt; &lt;url&gt;https://repo.spring.io/plugins-release/&lt;/url&gt; &lt;/pluginRepository&gt; &lt;/pluginRepositories&gt; 添加到 pom.xml。 spring-boot-starter-parent 的查找可能失败。

标签: java spring spring-boot maven spring-boot-maven-plugin


【解决方案1】:

我已经让你的构建工作了,但我不得不做出一些妥协。

我查看了 Spring 文档以了解您正在尝试的内容:

https://spring.io/guides/gs/rest-service/

然后我查看了示例的 pom.xml:

https://github.com/spring-guides/gs-rest-service/blob/master/complete/pom.xml

尽管文档说您可以使用 Java 1.8 或更高版本,但您仍需要使用 1.8。如果你再高一点,你必须在插件中指定属性编码,你不能这样做,因为你使用的是 Spring Boot 插件,而不是你可以在 pom.xml 中为你的项目配置的插件。

我还添加了比 Spring Boot 使用的更低版本的 maven-surefire-plugin。在此版本中,您会收到错误 [ERROR] There are test failures,但您没有运行任何测试。

我注释掉了 MySql 和 JPA 依赖项,除非您有数据库连接设置,否则它们将无法工作。

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>net.javaguides</groupId>
    <artifactId>spring-boot-restful-webservice</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-boot-restful-webservice</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
 <!-- 
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
 -->    
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </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>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <skipTests>false</skipTests>
                    <testFailureIgnore>true</testFailureIgnore>
                    <forkMode>once</forkMode>
                </configuration>
            </plugin>           
        </plugins>
    </build>
</project>

【讨论】:

  • 在评论 jpa 和连接依赖项后,我的也可以工作。
猜你喜欢
  • 1970-01-01
  • 2021-11-23
  • 1970-01-01
  • 2020-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-27
相关资源
最近更新 更多