How to parse the output of "mvn -version" programatically?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to parse the output of "mvn -version" programatically?

Akira Ajisaka
Hi Maven dev team,

Apache Yetus parses maven version by the following bash script and it no
longer works in Maven 3.5.0 or upper.
```
  maven_version=$(mvn --offline --version 2>/dev/null | head -n 1
2>/dev/null)
  maven_version=${maven_version##* }
```
https://github.com/apache/yetus/blob/rel/0.11.1/precommit/src/main/shell/test-patch.d/maven.sh#L258

After MNG-3507, the output contains control character and failed to parse
it. I'd like to fix this problem at
https://issues.apache.org/jira/browse/YETUS-957 but I'd like to hear the
best way to solve this problem from the Maven dev team.

Regards,
Akira Ajisaka
Reply | Threaded
Open this post in threaded view
|

Re: How to parse the output of "mvn -version" programatically?

Karl Heinz Marbaise-3
Hi,


On 25.03.20 09:02, Akira Ajisaka wrote:

> Hi Maven dev team,
>
> Apache Yetus parses maven version by the following bash script and it no
> longer works in Maven 3.5.0 or upper.
> ```
>    maven_version=$(mvn --offline --version 2>/dev/null | head -n 1
> 2>/dev/null)
>    maven_version=${maven_version##* }
> ```
> https://github.com/apache/yetus/blob/rel/0.11.1/precommit/src/main/shell/test-patch.d/maven.sh#L258

The first question I'm asking myself why do you need to findout the
Maven version?...

Apart from that it might be easier to do it that way:

MAVEN_VERSION=$(mvn
org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate
-Dexpression=maven.version -q -DforceStdout)

The MAVEN_VERSION will contain "3.6.3" for the appropriate maven
version. No control characters etc.

which works will all Maven versions 3.0.5...3.6.3

Kind regards
Karl Heinz Marbaise

>
> After MNG-3507, the output contains control character and failed to parse
> it. I'd like to fix this problem at
> https://issues.apache.org/jira/browse/YETUS-957 but I'd like to hear the
> best way to solve this problem from the Maven dev team.
>
> Regards,
> Akira Ajisaka
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]