Skip to content

[MPH-220] Evaluating an expression for use in a script fails on Maven 4.0.0-rc-1 #173

Open

Description

@jira-importer

Nils Breunese opened MPH-220 and commented

https://maven.apache.org/plugins/maven-help-plugin/evaluate-mojo.html shows that to use the value of an expression in a script, you can use this:

mvn help:evaluate -Dexpression=project.version -q -DforceStdout

I use a variant of this in a project and it works fine with Maven 3.9.9, but when I try it with Maven 4.0.0-rc-1, I no longer get the expected output.

Here is a small reproducer POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.example</groupId>
  <artifactId>foo</artifactId>
  <version>${revision}</version>
  <packaging>pom</packaging>

  <properties>
    <revision>1.0.0-SNAPSHOT</revision>
  </properties>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-help-plugin</artifactId>
        <version>3.5.1</version>
      </plugin>
    </plugins>
  </build>
</project>

This returns 1.0.0-SNAPSHOT with Maven 3.9.9:

❯ mvn help:evaluate -Dexpression=project.version -q -DforceStdout
1.0.0-SNAPSHOT

But there is no output with Maven 4.0.0-rc-1:

❯ mvn help:evaluate -Dexpression=project.version -q -DforceStdout

Note that when I omit the -q flag, then I do see the expected version in the output, but that output is of course not usable in an automated script.


Affects: 3.5.1

Activity

  1. jira-importer commented on Dec 17, 2024

    @jira-importer
    Author

    Nils Breunese commented

    I also see this issue with Maven 4.0.0-rc-2.

  2. jira-importer commented on Dec 17, 2024

    @jira-importer
    Author

    Tamas Cservenak commented

    This is a known issue, and same thing should be used as with mvnd: the new --raw-streams option.

    This is related how now Maven4 and mvnd fully utilize jline3.

  3. jira-importer commented on Dec 17, 2024

    @jira-importer
    Author

    Nils Breunese commented

    This seems to work indeed:

    ❯ mvn --raw-streams --quiet help:evaluate -Dexpression=project.version -DforceStdout
    1.0.0-SNAPSHOT
    

    Should this become the documented example for Maven 4 in the Maven Help Plugin docs at https://maven.apache.org/plugins/maven-help-plugin/evaluate-mojo.html then?

  4. added
    bug
    priority:major
    on Jun 14, 2025
  5. mthmulders commented on Jul 22, 2025

    @mthmulders

    This is a known issue, and same thing should be used as with mvnd: the new --raw-streams option.

    It is a breaking change though... If someone relies on -DforceStdout to only print the evaluated expression and nothing else, it will be different in Maven 4 compared to Maven 3.

    Would there be a way to enable --raw-streams when -DforceStdout is specified?

  6. cstamas commented on Jul 22, 2025

    @cstamas
    Member

    Maven 3.9.10+ supports the --raw-streams option as noop

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

    bugpriority:major

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions