1

Hi I have a problem with the encoding of my project.

When I run JUnit tests from eclipse, there are no failures. The problem is when I do maven > clean maven > install, one of the tests fails.

I have this string: "ADMINISTRACIÓN", and it's fine when i run the JUnit from eclipse, but I've printed the variable and when maven does the tests, the value of this string is: "ADMINISTRACI�N".

I've changed every property I could find of encoding in eclipse to UTF-8. -Configured the pom this way:

      (...)
      <project>
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            (...)
       </properties>
      </project>
      (...)
      <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.0</version>
            <configuration>
              <encoding>UTF-8</encoding>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
     </plugins>
     (...)

But the output is the same. I have a coworker that has the same project than me, and the same eclipse client and config, and her maven tests print accents with no trouble.

Any further ideas?

Thanks a lot!

Jose Climent
  • 57
  • 1
  • 10

2 Answers2

7

Try run your build with:

mvn -DargLine=-Dfile.encoding=UTF-8 clean insall

if help, you can configure surefire in project:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
            </configuration>
        </plugin>

Problem may occur because System.out use default system encoding, you can change this be setting file.encoding java property.

Slawomir Jaranowski
  • 7,381
  • 3
  • 25
  • 33
  • @Jose Or update Surefire, because this is a bug. You shouldn't need to set the file encoding: see https://issues.apache.org/jira/browse/SUREFIRE-951 – Tunaki Nov 24 '16 at 17:41
  • After trying all other options as mentioned above, this one worked for me too. In my case it was an ecoding issue (Characters: Ä, Ü, Ö) with JUnit under Windows. – Arek Apr 01 '19 at 11:07
  • I had this issue even with surefire 2.22.2 but the above plugin configuration still worked for me. Thanks! – Ralf Aug 21 '20 at 12:51
  • I set -Dfile.encoding=UTF-8 via JAVA_TOOL_OPTIONS, but maven-surefire-plugin ignores it. This answer worked for me. – Matthias Wiedemann Oct 01 '20 at 11:51
  • and if you are using jacoco you should consider this https://stackoverflow.com/questions/23190107/cannot-use-jacoco-jvm-args-and-surefire-jvm-args-together-in-maven – Matthias Wiedemann Oct 05 '20 at 08:19
1

I tried all settings mentioned in this post to build my project successfully however that didn't work for me. At last I was able to build my project successfully with mvn -DargLine=-Dfile.encoding=UTF-8 clean insall command.

Community
  • 1
  • 1
Divu
  • 11
  • 1