Fix console encoding on JDK 18 (Maven + general execution) #3836
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With JDK 18 the default charset for java was changed. Before this
change, the default charset (exposed as the system property
file.encoding) was platform specific. After the change the default
charset was unified to UTF-8 on all platforms.
Code that interacts with native APIs can use the system property
native.encoding to query the platform encoding and use that. And related
to this the same is true for applications interacting with the system
console.
The primarly affected platform is windows, as both mac OS and Linux
already default to UTF-8 as file encoding.
In this PR two areas are covered:
General execution (using "External Execution API"): The module already
allows users to specify the encoding to use. It used the default
enconding as a fallback, if none was specified. This fallback was
enhanced to query the native.encoding system property first. If it is
present, it will be used as default encoding (JDK 18+), if it is
missing, the original behavior using the default file encoding is
activated.
Maven target execution: maven target execution is basicly an external
execution, so the same considerations apply. In contrast to the
general execution API, the encoding for maven execution can't be
overriden, so both code path (input + output) are configured to use
the native.enconfig property if present or fallback to the default
file encoding.