Skip to content

Allow to configure the version file encoding#408

Open
Vampire wants to merge 1 commit intoresearchgate:mainfrom
Vampire:version-file-encoding
Open

Allow to configure the version file encoding#408
Vampire wants to merge 1 commit intoresearchgate:mainfrom
Vampire:version-file-encoding

Conversation

@Vampire
Copy link
Copy Markdown
Contributor

@Vampire Vampire commented Dec 8, 2025

Without this setting, the JVM default encoding is used. This can easily break files if they contain non-ASCII characters. A properties file for example by definintion is ISO-8859-1 encoded. Java 18+ use UTF-8 as default encoding if nothing else is configured. If you now manipulate the version file using UTF-8, it gets crippled if it contains non-ASCII characters.
With this new setting the encoding can be configured, with the appropriate default setting according to the default for the file.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a configurable encoding property for version property files to prevent corruption of non-ASCII characters when using Java 18+ (which defaults to UTF-8 encoding). The new versionPropertyFileEncoding property defaults to 'ISO-8859-1', the standard encoding for Java properties files.

Key Changes:

  • Added versionPropertyFileEncoding property to ReleaseExtension with ISO-8859-1 as the default
  • Updated all file read and write operations to use the configured encoding
  • Documented the new configuration option in README

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
ReleaseExtension.groovy Adds new versionPropertyFileEncoding property with ISO-8859-1 default
UnSnapshotVersion.groovy Updates properties file reading to use configured encoding
PrepareVersions.groovy Updates version writing to pass encoding parameter
BaseReleaseTask.groovy Updates writeVersion method signature and calls to use encoding parameter
PluginHelper.groovy Updates writeVersion method signature and all calls to use encoding parameter
README.md Documents the new configuration option with default value

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Hillkorn
Copy link
Copy Markdown
Collaborator

Hillkorn commented Jan 2, 2026

I thought java uses the encoding that is configured in the system via env variables for example but falls back to the ISO default in case there is nothing configured. If someone would have that configured we might break their files I guess?!?
Maybe gradle does it different here but I'm not 100% sure if this change doesn't beak existing projects.

@Hillkorn Hillkorn force-pushed the version-file-encoding branch from b4fe46a to 1bbbb40 Compare April 1, 2026 14:33
@Vampire
Copy link
Copy Markdown
Contributor Author

Vampire commented Apr 1, 2026

Ah, sorry, missed your question.

I thought java uses the encoding that is configured in the system via env variables for example but falls back to the ISO default in case there is nothing configured. If someone would have that configured we might break their files I guess?!?
Maybe gradle does it different here but I'm not 100% sure if this change doesn't beak existing projects.

Java uses the default encoding.
In older Java versions this is depending on the System encoding, so on most western european Windows systems it will by Cp1252, on most eastern european Windows systems it is another one, on most *nix systems it is UTF-8.
But even those are not guaranteed.

In newer Java versions the default changed to always be UTF-8 to fix that mess you always get by just running somewhere different and it suddenly behaves totally different.

WIth Gradle in specific it additionally depends on how you run Gradle iirc.
If you for example run the CLI with Java 8 but the daemon runs on Java 21, still the CLI Java version dictates the default encoding afair.

The encoding of a .properties file like gradle.properties though is defined by the format specification to be ISO-8859-1 always, except if you forcefully set an encoding when parsing and writing the file.
But the standard encoding is ISO-8859-1 and not the system default encoding whatever it is.

Also if you use some other file as version file, it most probably should also not follow the system encoding but have a fixedly defined encoding to not behave differently depending on where it is read.

In the - imho - quite unlikely case that someone for example has a gradle.properties file that is encoded in non ISO-8859-1, they can still configure the encoding then with this PR merged. But for the normal case there is currently no way to make the plugin behave properly, except for making sure the file only contains ASCII characters.

@Vampire
Copy link
Copy Markdown
Contributor Author

Vampire commented Apr 1, 2026

Btw.:
image

Without this setting, the JVM default encoding is used.
This can easily break files if they contain non-ASCII characters.
A properties file for example by definintion is ISO-8859-1 encoded.
Java 18+ use UTF-8 as default encoding if nothing else is configured.
If you now manipulate the version file using UTF-8, it gets crippled
if it contains non-ASCII characters.
With this new setting the encoding can be configured, with the
appropriate default setting according to the default for the file.
@Vampire Vampire force-pushed the version-file-encoding branch from 1bbbb40 to bf1c18d Compare April 22, 2026 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants