解决Spring boot 2.5.5 Maven 报错:Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources) on project myproject: Input length = 1 -> [Help 1]

时间:2022-08-16 17:48:05

把项目升级到Spring boot 2.5.5,在编译原理的项目时报错:

[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ myproject ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 3 resources
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.409 s
[INFO] Finished at: 2021-09-25T06:23:36+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources) on project myproject : 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


原因定位

原因是我们的*.properties文件使用了非UTF-8字符:

mail.fromPerson=�뾭�ʼ�

spring-boot-starter-parent配置的maven-resources-plugin,Spring Boot 默认使用 UTF-8,如前面的提示:

[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.

这是maven-resources-plugin:3.2.0的一个bug,在maven-resources-plugin:3.2.0之前的插件是能够兼容非UTF-8字符。spring boot 2.4升级到maven-resources-plugin:3.2.0,就出现了这个问题。

解决方法

方法一:把非UTF-8的字符改为UTF-8字符,或者删掉


方法二:在pom文件里降低maven-resources-plugin版本为3.1.0(推荐)

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>

方法三:排除对含有非UTF-8的资源,包含properties文件过滤

在pom文件添加插件配置:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<!-- 在此添加被排除过滤的文件 -->
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>properties</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>

参考:

https://github.com/spring-projects/spring-boot/issues/24346

https://*.com/questions/65910112/maven-clean-install-failed-to-execute-goal-org-apache-maven-pluginsmaven-resou/65910205