1

I'm familiar with how to set Maven to use a specific encoding, for example here. However, I want to know which encoding's Maven will support.

All I can find from Maven is a vague quote referring to mvn-resources-plugin that gives examples, but not an exhaustive list:

A character encoding scheme such as ASCII, UTF-8 or UTF-16 can be chosen to be used for the reading and writing of files.

To define 'supported', say I have a pom.xml that contains the following:

       <plugins>
            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.2.0</version>
            <configuration>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
    </plugins>

If I run the above with UTF-8, then everything runs fine, and this is considered supported. Specifically on mvn-resources-plugin I see:

[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ maven-encoding ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.

However, if I run Maven with an encoding of unknown, it is unsupported, as I get errors, for example:

[INFO] Building maven-encoding 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ maven-encoding ---
[INFO] Using 'unknown' encoding to copy filtered resources.
[INFO] Using 'unknown' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory <directory>
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ maven-encoding ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to <directory>
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.396 s
[INFO] Finished at: 2022-09-17T21:05:30+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project maven-encoding: Fatal error compiling: unknown -> [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

I note that it is interesting that it appears that mvn-resources-plugin does not seem to give me any errors, but mvn-compiler-plugin does.

I care about this because I need to be able to advise someone for which encodings that Maven would run. I have of course advised them that it would be sensible to ensure that their environment copes with UTF-8, or at least a common encoding, but I have been told that this is not guaranteed.

In answering the above, I anticipate we will also find out the answers to the following corollary questions:

  • Does the answer change on a plugin-by-plugin basis? (for example, mvn-compiler-plugin has a separate encoding setting to mvn-resources-plugin)

  • Is the set of supported encodings defined by Maven, or by the operating system that Maven is running on (or otherwise)?

Shaun Phillips
  • 111
  • 2
  • 9
  • Please show the full error output and not only excerpts... – khmarbaise Sep 17 '22 at 09:15
  • [A Guide to Maven Encoding](https://www.baeldung.com/maven-encoding)? – JosefZ Sep 17 '22 at 12:45
  • As pleased as I am to see my article as the top search result and referenced, as the author, I can tell you the answer to this question is not in there :) – Shaun Phillips Sep 17 '22 at 20:33
  • It looks like your java source code is not correctly encoded as given by the configuration. – khmarbaise Sep 22 '22 at 15:01
  • I'm aware that the source code encoding does not match the config, hence my question. I'm looking for an exhaustive list of encodings that each Maven plugin supports, or an answer that confirms it's OS dependent, or otherwise. – Shaun Phillips Sep 27 '22 at 13:54

0 Answers0