I18n issue with Chinese directly in java string on windows(MAC is fine!)

I think this is a java compiler nuance more than gradle to be honest, but hoping we can configure gradle to do the right thing here(intellij on windows does the right thing somehow??)

I wrote this test and the results per environment are here

  • Mac & (Intellij or Eclipse or Gradle) - test passes!!
  • Windows & Intellij - test passes
  • Windows & gradle - test fails

It took me a while to fine out it was the chinese string that is in the java file itself and then I finally ran into a log in the gradle build as well saying unmappable character (0x8F) for encoding windows-1252.

The error then has lots of incorrect characters. The test case is thus

indent preformatted text by 4 spaces

@Test

public void testChineseText() {

HttpFullRequest req = Requests. createRequest (KnownHttpMethod. GET , “/i18nBasic”);

req.addHeader( new Header(KnownHeaderName. ACCEPT_LANGUAGE , “zh-CN”));

CompletableFuture respFuture = http11Socket.send(req);

ResponseWrapper response = ResponseExtract. waitResponseAndWrap (respFuture);

response.assertStatusCode(KnownStatusCode. HTTP_200_OK );

response.assertContains(“你好, 这个是一个比较长的一个东西 我可以写比较多。 我在北京师范大学学了中文。 我喜欢完冰球”);

response.assertContains(“你好Dean,我们要去Italy”);

}


Gradle 5.3.1

Build time: 2019-03-28 09:09:23 UTC
Revision: f2fae6ba563cfb772c8bc35d31e43c59a5b620c3

Kotlin: 1.3.21
Groovy: 2.5.4
Ant: Apache Ant™ version 1.9.13 compiled on July 10 2018
JVM: 1.8.0_111 (Oracle Corporation 25.111-b14)
OS: Mac OS X 10.14.5 x86_64

any comments, should I open a bug since intellij somehow works just fine and java test files with chinese in them work just fine from the intellij perspective?

For now, I literally put an if statement in to not run on windows.

Also, I can create a branch so someone can easily check out this project and run and see if fail on windows if you like?

thanks,
Dean

A few options

  1. Tell the compiler which encoding to use
apply plugin: 'java'
tasks.withType(JavaCompile) {
   options.encoding = 'UTF-8'
}
  1. Put the expected strings into a properties file rather than directly in the .java file then read the properties file using the correct encoding

  2. Specify the strings in unicode so that they are not interpreted differently on Windows vs Unix