Skip to content

Add outputEncoding parameter to enable encoding conversion (MRESOURCES-232) - #531

Open
gnodet wants to merge 1 commit into
apache:masterfrom
gnodet:feat/output-encoding
Open

gnodet wants to merge 1 commit into
apache:masterfrom
gnodet:feat/output-encoding

Conversation

@gnodet

@gnodet gnodet commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a new outputEncoding plugin parameter that configures the character encoding used to write filtered resources. When set, the plugin reads source files with encoding and writes filtered output with outputEncoding, enabling lossless encoding conversion during the build.

Closes #335

Companion filtering PR: apache/maven-filtering#407

Use case

Converting a legacy EBCDIC or Latin-1 (ISO-8859-1) source tree to UTF-8 output without manually converting the source files:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-resources-plugin</artifactId>
  <configuration>
    <encoding>ISO-8859-1</encoding>
    <outputEncoding>UTF-8</outputEncoding>
  </configuration>
</plugin>

Or as a CLI property: -Dmaven.resources.outputEncoding=UTF-8

Per-resource encoding override via <encoding> / <outputEncoding> inside a <resource> block is also supported (requires the companion filtering PR to be released first).

Notes

  • The parameter only applies to filtered resources (<filtering>true</filtering>). Non-filtered files are always copied as raw bytes — encoding is irrelevant for them.
  • When outputEncoding is not set (the default), the same encoding is used for reading and writing, preserving full backward compatibility.
  • pom.xml references maven-filtering 4.0.0-beta-2-SNAPSHOT for local build; will be updated to the released version once the companion PR is merged and released.

Changes

  • ResourcesMojo: new @Parameter outputEncoding field wired into MavenResourcesExecution.setOutputEncoding()
  • src/it/MRESOURCES-232/: IT with a Latin-1 source file containing a filter token and an é character; verifies the output file is UTF-8-encoded with the token expanded and é surviving as 0xC3 0xA9

Closes #335

…S-232)

Add a new `outputEncoding` plugin parameter that configures the charset used
to write filtered resources. When set, the plugin reads files with `encoding`
(input) and writes them with `outputEncoding` (output), enabling lossless
encoding conversion during the build.

Use case: converting EBCDIC/Latin-1 legacy source trees to UTF-8 output
without manually converting the source files.

Configuration:
  <configuration>
    <encoding>ISO-8859-1</encoding>
    <outputEncoding>UTF-8</outputEncoding>
  </configuration>

Or as a CLI property:
  -Dmaven.resources.outputEncoding=UTF-8

Per-resource encoding override is also supported via `<encoding>` and
`<outputEncoding>` inside `<resource>` blocks (requires maven-filtering
4.0.0-beta-3-SNAPSHOT or later once released).

This parameter only applies to filtered resources (filtering=true). Non-filtered
files are always copied as raw bytes, so encoding is irrelevant for them.

NOTE: pom.xml bumped to maven-filtering 4.0.0-beta-2-SNAPSHOT (local dev only;
will be updated to released version before merge).

Relates to apache/maven-filtering (output-encoding PR)

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Clean feature addition — well-structured parameter, good Javadoc, solid IT with both string and byte-level verification. One inaccuracy to fix on the @since tag.

The SNAPSHOT dependency on maven-filtering 4.0.0-beta-2-SNAPSHOT is acknowledged in the PR description and expected to be updated before merge.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

* as raw bytes.
* </p>
*
* @since 3.4.1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Inaccurate @since tag — version 3.4.1 was never released (releases went 3.4.0 → 3.5.0 → 3.5.1). Since this PR targets master (the 4.x line), this should be:

Suggested change
* @since 3.4.1
* @since 4.0.0-beta-2

If backporting to the 3.x line as well, use the future 3.x release version there.

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.

[MRESOURCES-232] Resource copy filtering should use different encoding for source and output

2 participants