maven maven-surefire-plugin的乱码问题
今天项目中出现奇怪问题,在eclipse中直接运行TestNG时,全部都OK,但是执行mvn test时却失败.观察其输出日志,发现有乱码,怀疑是乱码导致.
最终在官网发现蛛丝马迹.
maven-surefire-plugin是运行mvn test时执行测试的插件,其有一个配置参数forkMode,默认为once,即表示每次运行test时,新建一个JVM进程运行所有test.这可能会导致乱码问题.首先将forkMode设置为never,即不新建.再运行mvn test,全部OK了.果然是这个问题!!
于是再找官方参数说明,发现了argLine参数,这个参数与forkMode一起使用,可以设置新建JVM时的JVM启动参数,于是设置<argLine>-Dfile.encoding=UTF-8</argLine>,明确指定一下JVM的file.encoding,并将forkMode从never改回once,还是每次新建一个JVM进程.再次运行mvn test,一起OK了,问题解决.
究其原因,是因为MAVEN的maven-surefire-plugin在新建JVM进程后,由于没有指定encoding,采用了OS的默认编码,导致读取UTF-8文件(测试类的sql脚本文件)时出现乱码,最终影响了TestNG的正确执行.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<argLine>${argLine} -Xmx1024m -Dfile.encoding=UTF-8</argLine>
<!--<skipTests>true</skipTests>-->
</configuration>
</plugin>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<configuration>
<jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
<fork>true</fork>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<configuration>
<destFile>target/jacoco-unit.exec</destFile>
<dataFile>target/jacoco-unit.exec</dataFile>
<excludes>
<exclude>**/entity/**</exclude>
<exclude>**/mapper/**</exclude>
<exclude>**/exception/**</exclude>
<exclude>**/*Application.class</exclude>
<exclude>**/*Builder.class</exclude>
<exclude>**/*BO.class</exclude>
<exclude>**/*DO.class</exclude>
<exclude>**/*DTO.class</exclude>
<exclude>**/*VO.class</exclude>
</excludes>
<!--<includes>
<include>**/service/**</include>
<include>**/controller/**</include>
</includes>-->
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!--这个check:对代码进行检测,控制项目构建成功还是失败-->
<execution>
<id>check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
<!--这个report:对代码进行检测,然后生成index.html在 target/site/index.html中可以查看检测的详细结果-->
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<argLine>${argLine} -Xmx1024m -Dfile.encoding=UTF-8</argLine>
<!--<skipTests>true</skipTests>-->
</configuration>
</plugin>
</plugins>
</build>
maven maven-surefire-plugin的乱码问题的更多相关文章
- maven surefire plugin介绍
示例 <!-- 测试运行器,生成测试报告 --> <plugin> <groupId>org.apache.maven.plugins</groupId> ...
- Maven系列--"maven-compiler-plugin"的使用、Maven之Surefire插件
一."maven-compiler-plugin"的使用 http://my.oschina.net/poorzerg/blog/206856 二.Maven之Surefire插件 ...
- [转]解决Maven报错"Plugin execution not covered by lifecycle configuration"
[转]解决Maven报错"Plugin execution not covered by lifecycle configuration" 导入Myabtis源码后,POM文件会报 ...
- [Maven]Maven 那点事儿
0. 前言 Jason Van Zyl,在 Java 十大风云人物排行榜上或许会看到他. 这兄弟是干嘛的? 他就是 Maven 的创始人,人们都尊称他为"Maven 他爸". 毋庸 ...
- Maven - Maven速成
Maven Maven是一个项目构建和管理工具,有助于开发者快速完成项目的配置,快速建立开发环境,从而提高开发效率. 管理项目构建(build)的生命周期(清理.编译.测试.打包.发布.部署.报告等) ...
- 学习Maven之Maven Surefire Plugin(JUnit篇)
1.maven-surefire-plugin是个什么鬼? 如果你执行过mvn test或者执行其他maven命令时跑了测试用例,你就已经用过maven-surefire-plugin了.maven- ...
- maven集成tomcat插件以及乱码解决
Maven已经是Java的项目管理标配,如何在JavaEE开发使用Maven调用Web应用,是很多同学关心的问题.本文将介绍,Maven如何介绍Tomcat插件. Maven Tomcat插件现在主要 ...
- Maven assembly插件输出文件乱码问题
使用Maven的<artifactId>maven-assembly-plugin</artifactId>插件导致输出的XML配置文件源文件的中文注释变成乱码,排查了多个地方 ...
- maven编译,控制台中文乱码解决方案
如下图,在使用maven运行后,在控制台看到中文展示乱码 出现这个的原因是源码使用UTF-8,但是maven编译的时候使用GBK标准,如下图 为了让maven编译的时候使用UTF-8标准,使用在p ...
- 记一次Maven发布Jar包中文乱码解决方法
Maven deploy 乱码 今天使用Maven发布Jar包时,发布功能都是正常的也成功上传到了仓库,就是项目跑越来后出中文中现了乱码: { "code": "SUCC ...
随机推荐
- iOS工厂模式使用小结
一.什么是工厂方法? 正式的解释是:在基类中定义创建对象的一个接口,让子类决定实例化哪个类.工厂方法让一个类的实例化延迟到子类中进行.工厂方法要解决的问题是对象的创建时机,它提供了一种扩展的策略,很好 ...
- 基于 Nginx 的大型互联网集群架构与实战方案
1. Nginx 负载均衡基础配置 首先,搭建一个基础的 Nginx 负载均衡器,用于将流量分发到多个后端服务器上. 步骤 1.1:安装 Nginx 在每台要作为负载均衡器的服务器上,安装 Nginx ...
- 1. react项目【前端】+C#【后端】从0到1
1.创建前端基础框架 1.1 前端创建 软件: 1.1.1 npx create-react-app pc ps:pc 是文件名 : 1.1.2 npm start 启动项目 2.创建后端基础框架 软 ...
- 有没有开发过⼀些vue插件?举例说说 - 批量引入插件
有过,项⽬开发的时间⻓了,沉淀了不少业务通⽤全局组件,想把他们统⼀进⾏注册,就封装了⼀个⼩ 插件 当时其实⼀开始也没有什么思路,后来扒了⼀下 elementUI的源码,仿了⼀下它的写法,流程我还⼤概记 ...
- 17 Transformer 的解码器(Decoders)——我要生成一个又一个单词
博客配套视频链接: https://space.bilibili.com/383551518?spm_id_from=333.1007.0.0 b 站直接看 配套 github 链接:https:// ...
- iframe嵌套PMM2.0
1.首先进入容器中 docker exec -it pmm-server /bin/bash 2.修改grafana.ini,允许匿名登录 vim /etc/grafana/grafana.ini 然 ...
- spring boot 与spring boot admin整合问题处理
1.在整合springboot admin server时,发现admin client无法注册到admin server上 查找原因后发现代码中报错:HttpMediaTypeNotAcceptab ...
- att&ack框架学习笔记5
深度解读ATT&CK框架前言:在上一篇文章中,我们简单介绍了这个由美国研究机构MITRE于2014年推出的新型攻击框架ATT&CK的相关概念.ATT&CK是将已知攻击者的行为汇 ...
- linux环境安装pip
1.下载pip安装包 https://files.pythonhosted.org/packages/ce/ea/9b445176a65ae4ba22dce1d93e4b5fe182f953df71a ...
- AI Undetect是什么?
标题:AI UNDETECT:超越AI检测的反检测神器 在数字时代,人工智能的飞速发展已经渗透到我们生活的各个领域,包括教育.科技.网络内容制作等.越来越多的人依赖AI来生成各种内容,从学术作业.论文 ...