Maven 全新安装:无法执行目标 org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources
Maven clean install: Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources
我不知道出了什么问题。尝试为大学项目安装 Maven。我已经按照说明安装了 maven here. Picture Environmental Variables, maven version in cmd 我还尝试删除 .m2 文件。当我尝试通过 InteliJ 中的插件安装 Maven 时,我收到消息:“进程终止”,没有额外信息。然后我尝试使用 mvn clean install 在终端上安装,我明白了。
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.college:sprinttool:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework.boot:spring-boot-starter-data-jpa:jar -> duplicate declaration of version (?) @ line 50, column 15
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework.boot:spring-boot-starter-test:jar -> duplicate declaration of version (?) @ line 55, column 15
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] -------------------< com.college:sprinttool >--------------------
[INFO] Building sprinttool 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ sprinttool ---
[INFO] Deleting E:\Code Practices\sprinttool\sprinttool\target
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ sprinttool ---
[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: 0.740 s
[INFO] Finished at: 2021-01-26T22:56:19+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources) on project sprinttool: 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
然后我运行“mvn clean install -X”获取更多信息,它还给出了这个。
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:64)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:564)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoExecutionException: Input length = 1
at org.apache.maven.plugins.resources.ResourcesMojo.execute (ResourcesMojo.java:362)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:64)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:564)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.shared.filtering.MavenFilteringException: Input length = 1
at org.apache.maven.shared.filtering.DefaultMavenFileFilter.copyFile (DefaultMavenFileFilter.java:113)
at org.apache.maven.shared.filtering.DefaultMavenResourcesFiltering.filterResources (DefaultMavenResourcesFiltering.java:262)
at org.apache.maven.plugins.resources.ResourcesMojo.execute (ResourcesMojo.java:356)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:64)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:564)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: java.nio.charset.MalformedInputException: Input length = 1
at java.nio.charset.CoderResult.throwException (CoderResult.java:274)
at sun.nio.cs.StreamDecoder.implRead (StreamDecoder.java:352)
at sun.nio.cs.StreamDecoder.read (StreamDecoder.java:188)
at java.io.InputStreamReader.read (InputStreamReader.java:181)
at java.io.BufferedReader.read1 (BufferedReader.java:210)
at java.io.BufferedReader.read (BufferedReader.java:287)
at java.io.BufferedReader.fill (BufferedReader.java:161)
at java.io.BufferedReader.read (BufferedReader.java:182)
at org.apache.maven.shared.filtering.BoundedReader.read (BoundedReader.java:85)
at org.apache.maven.shared.filtering.MultiDelimiterInterpolatorFilterReaderLineEnding.read (MultiDelimiterInterpolatorFilterReaderLineEnding.java:235)
at org.apache.maven.shared.filtering.MultiDelimiterInterpolatorFilterReaderLineEnding.read (MultiDelimiterInterpolatorFilterReaderLineEnding.java:197)
at java.io.Reader.read (Reader.java:229)
at org.apache.maven.shared.utils.io.IOUtil.copy (IOUtil.java:199)
at org.apache.maven.shared.utils.io.IOUtil.copy (IOUtil.java:181)
at org.apache.maven.shared.utils.io.FileUtils.copyFile (FileUtils.java:1908)
at org.apache.maven.shared.filtering.DefaultMavenFileFilter.copyFile (DefaultMavenFileFilter.java:98)
at org.apache.maven.shared.filtering.DefaultMavenResourcesFiltering.filterResources (DefaultMavenResourcesFiltering.java:262)
at org.apache.maven.plugins.resources.ResourcesMojo.execute (ResourcesMojo.java:356)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:64)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:564)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[ERROR]
[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.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 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.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.college</groupId>
<artifactId>sprinttool</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sprintplanningtool</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>15</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-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.3</version>
</dependency-->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</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-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>3.0.0</version>
</dependency-->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-bom</artifactId>
<version>5.3.3.RELEASE</version>
</dependency>
<!--dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.2.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator-annotation-processor</artifactId>
<version>6.0.2.Final</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.el</artifactId>
<version>2.2.6</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-compiler-plugin</artifactId>
<configuration>
<source>10</source>
<target>10</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
编辑:我使用 spring 启动初始化程序来创建项目。
这可能是一些最新版本的 Spring-boot(然后:Spring).
我有。解决方法是在 pom.xml
中放入这个更正的依赖项:
<!-- Pour contourner un bug à la génération par Spring-boot 2.4.x :
Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources) on project application-etude: Input length = 1 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>
异常的根本原因是某些资源包含不应过滤的资源(又名二进制文件)。正确的解决方案是为不应过滤的文件扩展名定义一个排除 like the following:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>pdf</nonFilteredFileExtension>
<nonFilteredFileExtension>swf</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
</plugins>
...
</build>
...
</project>
我遇到了同样的问题并通过添加 pom.xml 解决了它:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
这是帮助我解决问题的评论:
https://github.com/spring-projects/spring-boot/issues/24346#issuecomment-740345146
我遇到了同样的问题,并在我的 pom.xml 构建插件中使用以下更改修复了它。
<project>
...
<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>
</project>
您的某些资源包含不在 ISO-8859-1 代码页中的字符,这可能会在此处引起干扰:
at java.io.Reader.read (Reader.java:229)
at org.apache.maven.shared.utils.io.IOUtil.copy (IOUtil.java:199)
典型的错误可能是 .properties 文件中的重音字符。
我认为您同时定义了 application.property 和 application.yml。如果你想同时使用它们,请尝试插入 maven-resources-plugin
在我的例子中,错误发生是因为我有使用 ANSI 编码的属性文件,而 maven 试图使用 UTF-8。我通过将我的属性文件转换为 UTF-8 来修复它,然后 运行 mvn clean compile
.
在我的例子中,错误是由于重音“application.properties”
如果该工具只是给出一条消息说某个文件包含无效字符,那么修复此类错误肯定会容易得多...
备案,相关日志部分,在运行mvn clean package -e -X
之后,是这个:
[DEBUG] Using 'UTF-8' encoding to copy filtered resource 'application.properties'.
[DEBUG] filtering D:\Java\PreVendaAPI\src\main\resources\application.properties to D:\Java\PreVendaAPI\target\classes\application.properties
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
在 application.properties 文件中使用它肯定会起作用。
您需要排除二进制资源。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<propertiesEncoding>UTF-8</propertiesEncoding>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>xls</nonFilteredFileExtension>
<nonFilteredFileExtension>xlsx</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
我有同样的错误。从我的属性文件的注释中删除德语变音符号 ('ü') 后,应该过滤掉它们,问题就消失了!
使用这个依赖解决了我的这个问题
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
</dependency>
问题出在 maven-resources-plugin。这个插件的新版本没有旧版本那么宽松。不幸的是,当 Maven 构建失败(输入长度 = 1)时显示的错误消息只有在您从以前在 Java.
中遇到字符集问题的经验中识别出来时才有用。
您可以向 Maven 构建命令添加一些选项,以便它显示 DEBUG 级别的输出和构建失败时的完整堆栈跟踪。尝试将此作为诊断根本原因的第一步:
mvn -e -X clean test
在打开这些选项的情况下,它会在构建过程中向控制台输出大量信息。只需等到故障发生并检查控制台输出的结尾。你应该在最后看到一个完整的堆栈跟踪,这将更有意义。在堆栈跟踪之前,您还应该看到项目中导致错误的文件的名称。对我来说,我看到了这样的输出:
directory C:\GITROOT\conndev\repos\conn-lamp-server\src\test\resources
excludes []
includes []
[DEBUG] ignoreDelta true
[INFO] Copying 3 resources
[DEBUG] Copying file application-inttest.properties
[DEBUG] file application-inttest.properties has a filtered file extension
[DEBUG] Using 'UTF-8' encoding to copy filtered resource 'application-inttest.properties'.
[DEBUG] filtering C:\GITROOT\conndev\repos\conn-lamp-server\src\test\resources\application-inttest.properties to C:\GITROOT\conndev\repos\conn-lamp-server\target\test-classes\application-inttest.properties
[DEBUG] Copying file DummyExcelFile.xls
[DEBUG] file DummyExcelFile.xls has a filtered file extension
[DEBUG] Using 'UTF-8' encoding to copy filtered resource 'DummyExcelFile.xls'.
[DEBUG] filtering C:\GITROOT\conndev\repos\conn-lamp-server\src\test\resources\DummyExcelFile.xls to C:\GITROOT\conndev\repos\conn-lamp-server\target\test-classes\DummyExcelFile.xls
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 37.927 s
[INFO] Finished at: 2022-04-26T10:11:09-03:00
[INFO] ------------------------------------------------------------------------
现在我知道我的测试资源目录中的一个文件是问题所在:
src\test\resources\DummyExcelFile.xls
资源插件的旧版本一定已经悄悄地抑制了这个问题。我不会在这里包含完整的堆栈跟踪,但这是堆栈跟踪中的重要行:
Caused by: java.nio.charset.MalformedInputException: Input length = 1
我以前见过这个。当 Java 'reader' class 无法读取文本文件时会发生这种情况,因为该文件包含一个或多个对 reader 使用的字符集无效的字符。在我的例子中,它试图将二进制文件作为文本读取,所以这永远行不通!如果您的文本文件包含不寻常的字符(例如带有重音符号的欧洲语言)并且这些字符对于您使用的字符集(例如 UTF-8)无效,则可能会发生同样的问题。所有这些问题都可以通过一些POM配置来解决。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<propertiesEncoding>UTF-8</propertiesEncoding>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>xls</nonFilteredFileExtension>
<nonFilteredFileExtension>zip</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
如果您使用的是与 UTF-8 不同的字符集,只需在上面的 XML 代码段中替换您的字符集。对您希望 maven-resource-plugin 在过滤时忽略的任何文件扩展名执行相同的操作。
请注意,我有意省略了上面 maven-resources-plugin 块的 <version>
。这是因为我在我的 POM 中使用 spring-boot-starter-parent
并且许多依赖项的版本是从父项继承的。如果您不使用父版本,则必须明确设置要使用的版本。
我在 application.properties 文件的注释中写入非 utf-8 字符时遇到了同样的错误。我删除了那些字符,它正在工作!
今天出现了这条消息,这是我解决它的方法:
我用mvn这样分析资源:
mvn -X process-test-resources
这样 mvn 返回了导致错误的文件的名称:
[DEBUG] filtering .../messages.properties
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: x
[INFO] Finished at: y
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources) on foo: Input length = 1 ->
原来 messages.properties 包含未正确转义的特殊字符。所以我在 i18n 文件中对它们进行了转义,之后我就可以再次构建了。
我不知道出了什么问题。尝试为大学项目安装 Maven。我已经按照说明安装了 maven here. Picture Environmental Variables, maven version in cmd 我还尝试删除 .m2 文件。当我尝试通过 InteliJ 中的插件安装 Maven 时,我收到消息:“进程终止”,没有额外信息。然后我尝试使用 mvn clean install 在终端上安装,我明白了。
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.college:sprinttool:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework.boot:spring-boot-starter-data-jpa:jar -> duplicate declaration of version (?) @ line 50, column 15
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework.boot:spring-boot-starter-test:jar -> duplicate declaration of version (?) @ line 55, column 15
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] -------------------< com.college:sprinttool >--------------------
[INFO] Building sprinttool 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ sprinttool ---
[INFO] Deleting E:\Code Practices\sprinttool\sprinttool\target
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ sprinttool ---
[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: 0.740 s
[INFO] Finished at: 2021-01-26T22:56:19+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources) on project sprinttool: 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
然后我运行“mvn clean install -X”获取更多信息,它还给出了这个。
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:64)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:564)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoExecutionException: Input length = 1
at org.apache.maven.plugins.resources.ResourcesMojo.execute (ResourcesMojo.java:362)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:64)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:564)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.shared.filtering.MavenFilteringException: Input length = 1
at org.apache.maven.shared.filtering.DefaultMavenFileFilter.copyFile (DefaultMavenFileFilter.java:113)
at org.apache.maven.shared.filtering.DefaultMavenResourcesFiltering.filterResources (DefaultMavenResourcesFiltering.java:262)
at org.apache.maven.plugins.resources.ResourcesMojo.execute (ResourcesMojo.java:356)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:64)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:564)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: java.nio.charset.MalformedInputException: Input length = 1
at java.nio.charset.CoderResult.throwException (CoderResult.java:274)
at sun.nio.cs.StreamDecoder.implRead (StreamDecoder.java:352)
at sun.nio.cs.StreamDecoder.read (StreamDecoder.java:188)
at java.io.InputStreamReader.read (InputStreamReader.java:181)
at java.io.BufferedReader.read1 (BufferedReader.java:210)
at java.io.BufferedReader.read (BufferedReader.java:287)
at java.io.BufferedReader.fill (BufferedReader.java:161)
at java.io.BufferedReader.read (BufferedReader.java:182)
at org.apache.maven.shared.filtering.BoundedReader.read (BoundedReader.java:85)
at org.apache.maven.shared.filtering.MultiDelimiterInterpolatorFilterReaderLineEnding.read (MultiDelimiterInterpolatorFilterReaderLineEnding.java:235)
at org.apache.maven.shared.filtering.MultiDelimiterInterpolatorFilterReaderLineEnding.read (MultiDelimiterInterpolatorFilterReaderLineEnding.java:197)
at java.io.Reader.read (Reader.java:229)
at org.apache.maven.shared.utils.io.IOUtil.copy (IOUtil.java:199)
at org.apache.maven.shared.utils.io.IOUtil.copy (IOUtil.java:181)
at org.apache.maven.shared.utils.io.FileUtils.copyFile (FileUtils.java:1908)
at org.apache.maven.shared.filtering.DefaultMavenFileFilter.copyFile (DefaultMavenFileFilter.java:98)
at org.apache.maven.shared.filtering.DefaultMavenResourcesFiltering.filterResources (DefaultMavenResourcesFiltering.java:262)
at org.apache.maven.plugins.resources.ResourcesMojo.execute (ResourcesMojo.java:356)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:64)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:564)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[ERROR]
[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.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 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.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.college</groupId>
<artifactId>sprinttool</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sprintplanningtool</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>15</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-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.3</version>
</dependency-->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</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-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>3.0.0</version>
</dependency-->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-bom</artifactId>
<version>5.3.3.RELEASE</version>
</dependency>
<!--dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.2.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator-annotation-processor</artifactId>
<version>6.0.2.Final</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.el</artifactId>
<version>2.2.6</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-compiler-plugin</artifactId>
<configuration>
<source>10</source>
<target>10</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
编辑:我使用 spring 启动初始化程序来创建项目。
这可能是一些最新版本的 Spring-boot(然后:Spring).
我有。解决方法是在 pom.xml
中放入这个更正的依赖项:
<!-- Pour contourner un bug à la génération par Spring-boot 2.4.x :
Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources) on project application-etude: Input length = 1 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>
异常的根本原因是某些资源包含不应过滤的资源(又名二进制文件)。正确的解决方案是为不应过滤的文件扩展名定义一个排除 like the following:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>pdf</nonFilteredFileExtension>
<nonFilteredFileExtension>swf</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
</plugins>
...
</build>
...
</project>
我遇到了同样的问题并通过添加 pom.xml 解决了它:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
这是帮助我解决问题的评论: https://github.com/spring-projects/spring-boot/issues/24346#issuecomment-740345146
我遇到了同样的问题,并在我的 pom.xml 构建插件中使用以下更改修复了它。
<project>
...
<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>
</project>
您的某些资源包含不在 ISO-8859-1 代码页中的字符,这可能会在此处引起干扰:
at java.io.Reader.read (Reader.java:229)
at org.apache.maven.shared.utils.io.IOUtil.copy (IOUtil.java:199)
典型的错误可能是 .properties 文件中的重音字符。
我认为您同时定义了 application.property 和 application.yml。如果你想同时使用它们,请尝试插入 maven-resources-plugin
在我的例子中,错误发生是因为我有使用 ANSI 编码的属性文件,而 maven 试图使用 UTF-8。我通过将我的属性文件转换为 UTF-8 来修复它,然后 运行 mvn clean compile
.
在我的例子中,错误是由于重音“application.properties”
如果该工具只是给出一条消息说某个文件包含无效字符,那么修复此类错误肯定会容易得多...
备案,相关日志部分,在运行mvn clean package -e -X
之后,是这个:
[DEBUG] Using 'UTF-8' encoding to copy filtered resource 'application.properties'.
[DEBUG] filtering D:\Java\PreVendaAPI\src\main\resources\application.properties to D:\Java\PreVendaAPI\target\classes\application.properties
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
在 application.properties 文件中使用它肯定会起作用。
您需要排除二进制资源。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<propertiesEncoding>UTF-8</propertiesEncoding>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>xls</nonFilteredFileExtension>
<nonFilteredFileExtension>xlsx</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
我有同样的错误。从我的属性文件的注释中删除德语变音符号 ('ü') 后,应该过滤掉它们,问题就消失了!
使用这个依赖解决了我的这个问题
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
</dependency>
问题出在 maven-resources-plugin。这个插件的新版本没有旧版本那么宽松。不幸的是,当 Maven 构建失败(输入长度 = 1)时显示的错误消息只有在您从以前在 Java.
中遇到字符集问题的经验中识别出来时才有用。您可以向 Maven 构建命令添加一些选项,以便它显示 DEBUG 级别的输出和构建失败时的完整堆栈跟踪。尝试将此作为诊断根本原因的第一步:
mvn -e -X clean test
在打开这些选项的情况下,它会在构建过程中向控制台输出大量信息。只需等到故障发生并检查控制台输出的结尾。你应该在最后看到一个完整的堆栈跟踪,这将更有意义。在堆栈跟踪之前,您还应该看到项目中导致错误的文件的名称。对我来说,我看到了这样的输出:
directory C:\GITROOT\conndev\repos\conn-lamp-server\src\test\resources
excludes []
includes []
[DEBUG] ignoreDelta true
[INFO] Copying 3 resources
[DEBUG] Copying file application-inttest.properties
[DEBUG] file application-inttest.properties has a filtered file extension
[DEBUG] Using 'UTF-8' encoding to copy filtered resource 'application-inttest.properties'.
[DEBUG] filtering C:\GITROOT\conndev\repos\conn-lamp-server\src\test\resources\application-inttest.properties to C:\GITROOT\conndev\repos\conn-lamp-server\target\test-classes\application-inttest.properties
[DEBUG] Copying file DummyExcelFile.xls
[DEBUG] file DummyExcelFile.xls has a filtered file extension
[DEBUG] Using 'UTF-8' encoding to copy filtered resource 'DummyExcelFile.xls'.
[DEBUG] filtering C:\GITROOT\conndev\repos\conn-lamp-server\src\test\resources\DummyExcelFile.xls to C:\GITROOT\conndev\repos\conn-lamp-server\target\test-classes\DummyExcelFile.xls
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 37.927 s
[INFO] Finished at: 2022-04-26T10:11:09-03:00
[INFO] ------------------------------------------------------------------------
现在我知道我的测试资源目录中的一个文件是问题所在:
src\test\resources\DummyExcelFile.xls
资源插件的旧版本一定已经悄悄地抑制了这个问题。我不会在这里包含完整的堆栈跟踪,但这是堆栈跟踪中的重要行:
Caused by: java.nio.charset.MalformedInputException: Input length = 1
我以前见过这个。当 Java 'reader' class 无法读取文本文件时会发生这种情况,因为该文件包含一个或多个对 reader 使用的字符集无效的字符。在我的例子中,它试图将二进制文件作为文本读取,所以这永远行不通!如果您的文本文件包含不寻常的字符(例如带有重音符号的欧洲语言)并且这些字符对于您使用的字符集(例如 UTF-8)无效,则可能会发生同样的问题。所有这些问题都可以通过一些POM配置来解决。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<propertiesEncoding>UTF-8</propertiesEncoding>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>xls</nonFilteredFileExtension>
<nonFilteredFileExtension>zip</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
如果您使用的是与 UTF-8 不同的字符集,只需在上面的 XML 代码段中替换您的字符集。对您希望 maven-resource-plugin 在过滤时忽略的任何文件扩展名执行相同的操作。
请注意,我有意省略了上面 maven-resources-plugin 块的 <version>
。这是因为我在我的 POM 中使用 spring-boot-starter-parent
并且许多依赖项的版本是从父项继承的。如果您不使用父版本,则必须明确设置要使用的版本。
我在 application.properties 文件的注释中写入非 utf-8 字符时遇到了同样的错误。我删除了那些字符,它正在工作!
今天出现了这条消息,这是我解决它的方法:
我用mvn这样分析资源:
mvn -X process-test-resources
这样 mvn 返回了导致错误的文件的名称:
[DEBUG] filtering .../messages.properties
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: x
[INFO] Finished at: y
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources) on foo: Input length = 1 ->
原来 messages.properties 包含未正确转义的特殊字符。所以我在 i18n 文件中对它们进行了转义,之后我就可以再次构建了。