sbt test encoding hickup

谁都会走 提交于 2019-12-10 21:19:48

问题


I am writing a Java library for the work with geo-coordinates and the tests are implemented with specs2 in Scala. I have many tests that do String comparisons against Strings that include the degree symbol ° (which is a non-ASCII character).

If I run these tests from within IntelliJ, they all pass. They also pass on Travis CI. But if I run sbt test (sbt 11.3) from my Power Shell (Windows x64), all those tests fail and the console shows malformed Strings like shown in the screen shot:

What could be the issue, and how can I fix it? I checked that the files are UTF8-encoded. Also note that changing my Java configuration would not help much, since the tests just have to run if someone else clones the repository (so any solution that solves the problem only on my system isn't going to help). But I have absolutely no clue what is going wrong here...


回答1:


Are your degree symbols encoded directly in the source file?

If so, I suspect you may have some encoding issues (possibly source files are being interpreted as UTF-8 in IntelliJ and CP1252 when compiled by SBT).

You could either try changing the degree symbols to '\u00B0' and recompiling, or alternatively you could try setting the source file encoding in SBT with javacOptions ++= Seq("-encoding", "UTF-8").

FWIW, the compiler (and runtime) uses the default encoding for source (and other) file I/O, unless told otherwise. The default encoding for Windows is CP1252.

You can tell the javac compiler to use an alternative encoding with the -encoding UTF-8 option, and the runtime with -Dfile.encoding=UTF-8.

Through Google, I also found some information on how to do this on a system-wide basis here (untested by me).



来源:https://stackoverflow.com/questions/12712216/sbt-test-encoding-hickup

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!