Skip to content

useProjectFiles bypasses Velocity rendering for .vm overrides #267

Description

@elharo

Summary

copyProjectRootIfExists() copies a project file over a remote bundle resource with a plain, un-rendered copy — no Velocity processing. When a local file overrides a remote .vm template, the raw Velocity syntax is emitted into the output.

src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java:666-679

private boolean copyProjectRootIfExists(File outputFile, String bundleResourceName) throws IOException {
    if (!useProjectFiles) {
        return false;
    }
    File source = new File(project.getBasedir(), bundleResourceName);
    if (source.exists()) {
        getLog().debug("Use project file  + source +  as resource");
        FilteringUtils.copyFile(source, outputFile, null, null);
        return true;
    }
    return false;
}

Problems

  1. The copy uses FilteringUtils.copyFile(source, outputFile, null, null) — no Velocity mergeTemplate/evaluate. A remote .vm template (foo.txt.vm) overridden by a local foo.txt will be copied verbatim, leaving $project.name etc. unexpanded in the output.
  2. It only looks for <basedir>/<name>, ignoring <basedir>/<name>.vm — inconsistent with copyResourceIfExists() (:614-664) which checks both <name> and <name>.vm and renders the .vm variant via Velocity.

This feature is new in 3.3.0, so the inconsistency vs. the established resource-directory override path is surprising.

Suggested fix

Mirror the logic of copyResourceIfExists(): check for both <name> and <name>.vm, and when the .vm file is used, render it through velocity.evaluate(...) with the same encoding handling.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions