Skip to content

Allow defining complex expression like in interactive mode - #132

Merged
slawekjaranowski merged 1 commit into
apache:masterfrom
ggkochanski:master
Nov 3, 2025
Merged

slawekjaranowski merged 1 commit into
apache:masterfrom
ggkochanski:master

Conversation

@ggkochanski

@ggkochanski ggkochanski commented May 23, 2025 •

Copy link
Copy Markdown

Overlapping parameter expression for goal help:evaluate by default:
handleResponse("${" + expression + "}", output);

limits usage for more complex expressions, e.g.
mvn help:evaluate -Dexpression='project_version=${project.version}'

which currently fails with message:
null object or invalid expression

Skipping the overlapping when an expression already contains string '${' removes this limitation and allows to define expression in the same way as in the interactive mode:
echo 'project_version=${project.version}'|mvn help:evaluate

Comment thread src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java Outdated
Comment thread src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java Outdated
Comment thread src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java Outdated
Comment thread src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java Outdated
Comment thread src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java Outdated
@slawekjaranowski slawekjaranowski added the enhancement New feature or request label Nov 3, 2025
@slawekjaranowski

Copy link
Copy Markdown
Member

@ggkochanski please add at least one line from template to PR description

[ ] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)

https://github.com/apache/maven-help-plugin/blob/master/.github/pull_request_template.md

@ggkochanski

Copy link
Copy Markdown
Author
  • done

@slawekjaranowski
slawekjaranowski merged commit ea12a9d into apache:master Nov 3, 2025
20 checks passed
@github-actions github-actions Bot added this to the 3.5.2 milestone Nov 3, 2025
@ggkochanski

Copy link
Copy Markdown
Author

It appears that property expression

@Parameter(property = "expression")
private String expression;

is already resolved when it goes to EvaluateMojo.execute()

e.g. executing
-Dexpression='project_version=${project.version}'

causes that the value of injected parameter expression is already resolved:
project_version=3.5.2-SNAPSHOT

and overlapping it with ${} does not do any good 😢

It overlaps already resolved expression with '${}' and tries to handle expression ${project_version=3.5.2-SNAPSHOT}, which fails with message

null object or invalid expression

However, the workaround exists 😛
passing property through additional parameter does the job, e.g.
-Dexpression='project_version=$${ver_property}' -Dver_property='{project.version}'
outputs desired value:
project_version=3.5.2-SNAPSHOT

@slachiewicz

Copy link
Copy Markdown
Member

should we revert this change?

@ggkochanski

Copy link
Copy Markdown
Author

should we revert this change?

Please keep it; it ultimately serves its purpose: you can prepare properties like format (or any other) within a single goal. This eliminates the need to use standard input, which is not always possible, e.g., during release

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants