Getting Started with Maven | Miscellaneous | Encoding Settings
Sometimes you may want to configure the encoding for source files and report output in Maven’s pom.xml. There are several ways to configure it, but this article covers a simple method.
How to Configure It
Configure it in the properties section of pom.xml as follows.
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
If you configure it in properties, you can omit encoding settings for plugins, such as the following.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
Plugins such as maven-resources-plugin and maven-compiler-plugin refer to the encoding settings in properties.
Supplement
If you do not configure encoding, Maven prints a warning like the following when it runs.
...omitted...
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ poml
---
[WARNING] Using platform encoding (MS932 actually) to copy filtered resources, i.e. build is platform dependent!
...omitted...
References
- Specifying a character encoding scheme - Maven Resources Plugin
- Optional Parameters - Maven Compiler Plugin