maven-exec-plugin problem

28 views
Skip to first unread message

Jörg Hohwiller

unread,
Jun 30, 2019, 5:38:41 PM6/30/19
to mojohaus-dev
Hi there,
in order to determine the version(s) of a maven project, several answers on stackoverflow, etc. lead to calling:
mvn -q exec:exec -Dexec.executable=echo -Dexec.args='${project.version}'

However, if in case the maven project (or one of its modules) itself has the maven-exec-plugin configured in its build section, the above command fails.
For some reason here maven tries to invoke that exec-plugin execution as well and ends up with some error like:

[ERROR] Unknown lifecycle phase "1.0.0-beta1-SNAPSHOT". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
...
[ERROR] Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
    at org.apache.commons.exec.DefaultExecutor.executeInternal (DefaultExecutor.java:404)
    at org.apache.commons.exec.DefaultExecutor.execute (DefaultExecutor.java:166)
    at org.codehaus.mojo.exec.ExecMojo.executeCommandLine (ExecMojo.java:804)

Is there some smart guy out there who could give me a hint how to avoid this error (stop maven from executing the build execution of exec plugin triggered from "mvn exec:exec" call)?
Or as an alternative give me a better hint how to determine the version of the current maven project from bash without manually parsing ./mvn/maven.config as well as pom.xml files, etc. ending up in reimplementing maven...

Thanks
  Jörg

Alexei Znamensky

unread,
Jun 30, 2019, 8:45:40 PM6/30/19
to mojohaus-dev
Hi Jörg,

You will want to:

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


Cheers,
Alexei

Jörg Hohwiller

unread,
Jul 2, 2019, 8:18:18 AM7/2/19
to mojohaus-dev
Hi Alexei,

Awesome!
This does not solve all my problems as I need to check for a convergent version (excluding potential "dev-SNAPSHOT" version of parents that do not get released) throughout the reactor of a multi-module project but you gave me the right hint and missing link to get it done.

Thank you so much
  Jörg

Jörg Hohwiller

unread,
Jul 2, 2019, 8:37:32 AM7/2/19
to mojohaus-dev
Hi again,

as always murphies law applies.
# mvn help:evaluate -Dexpression=project.version -q -DforceStdout
# mvn -q exec:exec -Dexec.executable=echo -Dexec.args='${project.version}'
1.0.0-SNAPSHOT
1.0.0-SNAPSHOT
1.0.0-SNAPSHOT
1.0.0-SNAPSHOT
1.0.0-SNAPSHOT
#

So do not ask me why but IMHO help:evaluate does not work together with ci-fiendly-maven (https://maven.apache.org/maven-ci-friendly.html).

Is that a bug of maven-help-plugin?
Or is there anything I can do about it?

Thanks
  Jörg

Jörg Hohwiller

unread,
Jul 2, 2019, 8:39:35 AM7/2/19
to mojohaus-dev
Hi,

it is not even ci-friendly. I have the version configured statically in that project:

Not a clue what is going wrong with help-plugin in this setup...
Any hit to shed a light would be highly appreciated...

Cheers
  Jörg

Jörg Hohwiller

unread,
Jul 2, 2019, 8:41:56 AM7/2/19
to mojohaus-dev
very strange:

➜  keywi git:(feature/fix-jpa-setup) ✗ mvn help:evaluate -Dexpression=project.version -DforceStdout
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] keywi                                                              [pom]
[INFO] keywi-api                                                          [jar]
[INFO] keywi-core                                                         [jar]
[INFO] keywi-server                                                       [war]
[INFO] keywi-client                                                       [jar]
[INFO]
[INFO] ----------------------< com.devonfw.keywi:keywi >-----------------------
[INFO] Building keywi 1.0.0-SNAPSHOT                                      [1/5]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-help-plugin:2.2:evaluate (default-cli) @ keywi ---
[INFO] No artifact parameter specified, using 'com.devonfw.keywi:keywi:pom:1.0.0-SNAPSHOT' as project.
[INFO]
1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for keywi 1.0.0-SNAPSHOT:
[INFO]
[INFO] keywi .............................................. SUCCESS [  0.190 s]
[INFO] keywi-api .......................................... SKIPPED
[INFO] keywi-core ......................................... SKIPPED
[INFO] keywi-server ....................................... SKIPPED
[INFO] keywi-client ....................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.740 s
[INFO] Finished at: 2019-07-02T14:40:09+02:00
[INFO] ------------------------------------------------------------------------
➜  keywi git:(feature/fix-jpa-setup) ✗ mvn help:evaluate -Dexpression=project.version -q -DforceStdout
➜  keywi git:(feature/fix-jpa-setup) ✗

So in this project -q also seems to suppress -DforceStdout
I have no clue what impact is causing this...
In some other projects it is working.
Anyhow does not seem to be a universal solution either...

Jörg Hohwiller

unread,
Jul 2, 2019, 8:44:22 AM7/2/19
to mojohaus-dev
gotcha:


➜  keywi git:(feature/fix-jpa-setup) ✗ mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.version -q -DforceStdout
1.0.0-SNAPSHOT%

Mirko Friedenhagen

unread,
Jul 5, 2019, 2:35:57 AM7/5/19
to mojoha...@googlegroups.com
You could try the exec-maven-plugin approach and use mvn -N to restrict the execution to the reactor parent *if* all your reactor modules have the same version.

Concerning the help-Plugin : forceStdout is a very recent feature, you need at least version 3.1.0, try:
mvn -N -q org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -DforceStdout -Dexpression=project.version

Best Regards
Mirko Friedenhagen

Sent from my mobile

Am 02.07.19 um 14:39 schrieb 'Jörg Hohwiller' via mojohaus-dev
> --
> You received this message because you are subscribed to the Google Groups "mojohaus-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mojohaus-dev...@googlegroups.com.
> To post to this group, send email to mojoha...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/mojohaus-dev/3985cba0-2f5c-4d24-a7c4-9c024a24c221%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages