Springboot專案Maven打包報錯:Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources
阿新 • • 發佈:2021-06-14
今天新建一個前端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版本。