Springboot项目Maven打包报错:Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:r

Posted 蒲公英不是梦

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Springboot项目Maven打包报错:Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:r相关的知识,希望对你有一定的参考价值。

今天新建一个前端demo项目,需要引入thymeleaf依赖,项目运行和测试都正常,但是打包的时候却报以下错误:

D:\\Server\\Java\\jdk1.8.0_231\\bin\\java.exe -Dmaven.multiModuleProjectDirectory=E:\\Private\\homework-parent\\template-layui -Dmaven.home=E:\\Tools\\Maven\\apache-maven-3.6.3 -Dclassworlds.conf=E:\\Tools\\Maven\\apache-maven-3.6.3\\bin\\m2.conf "-Dmaven.ext.class.path=D:\\Software\\JetBrains\\IntelliJ IDEA 2019.3.3\\plugins\\maven\\lib\\maven-event-listener.jar" "-javaagent:D:\\Software\\JetBrains\\IntelliJ IDEA 2019.3.3\\lib\\idea_rt.jar=14887:D:\\Software\\JetBrains\\IntelliJ IDEA 2019.3.3\\bin" -Dfile.encoding=UTF-8 -classpath E:\\Tools\\Maven\\apache-maven-3.6.3\\boot\\plexus-classworlds-2.6.0.jar;E:\\Tools\\Maven\\apache-maven-3.6.3\\boot\\plexus-classworlds.license org.codehaus.classworlds.Launcher -Didea.version2019.3.3 -s E:\\Tools\\Maven\\apache-maven-3.6.3\\conf\\settings.xml -Dmaven.repo.local=E:\\Tools\\Repository package
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------< org.dandelion:template-layui >--------------------
[INFO] Building template-layui 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ template-layui ---
[INFO] Using \'UTF-8\' encoding to copy filtered resources.
[INFO] Using \'UTF-8\' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.171 s
[INFO] Finished at: 2021-06-14T07:55:24+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources) on project template-layui: Input length = 1 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

根据网上获取到的信息说是pom文件中没有引入maven-resources-plugin插件,于是我把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 http://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.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>org.dandelion</groupId>
    <artifactId>template-layui</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <java.version>1.8</java.version>
        <mybatis.version>1.3.2</mybatis.version>
        <mysql.version>5.1.48</mysql.version>
        <nekohtml.version>1.9.22</nekohtml.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.nekohtml</groupId>
            <artifactId>nekohtml</artifactId>
            <version>${nekohtml.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>${mybatis.version}</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </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-resources-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

根据报错信息得知引入maven插件maven-resources-plugin时版本可能冲突,我用的springboot版本时2.4.4,而这里用到的maven插件是3.2.0。

尝试将maven插件改为3.1.0,再次打包成功。

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.1.0</version>
        </plugin>
    </plugins>
</build>

所以问题是使用springboot2.4.x版本引入maven的resource插件时需要指定3.1.0版本。

以上是关于Springboot项目Maven打包报错:Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:r的主要内容,如果未能解决你的问题,请参考以下文章

idea 打包springboot项目报错:404

SpringBoot+Maven 多模块项目的构建运行打包

IDEA使用Maven打包Spark项目报错,求大神指点下

Spring boot 打包为war包报错:提示缺少web.xml

SpringBoot+Docker项目打包(jar)和部署

SpringBoot简单打包部署(附工程)