-2

I have a pom file. I want to read the version of the first dependency in the dependencies tag and use that version to tag our docker image.

I am using this command to get the project version.

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

I want to get the version of the first dependency using command line , and from there it will passed onto the docker tag and docker push.

enter image description here

  • 3
    Codes and logs should not be attached as images, but in text format. See the following guide. [how-to-ask](https://stackoverflow.com/help/how-to-ask) / [do-not-upload-images-of-code-errors](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question/285557#285557) – myeongkil kim Dec 21 '20 at 09:29
  • 2
    also, searching before the question is essential. Have you checked the link? [how-to-get-maven-project-version](https://stackoverflow.com/questions/3545292/how-to-get-maven-project-version-to-the-bash-command-line) – myeongkil kim Dec 21 '20 at 09:31
  • Why do you like to get that version? And put that into a docker image? In your build the version of your artifact will always be 5.0.0 based on the given parent and not overriding the version.... – khmarbaise Dec 21 '20 at 15:28

1 Answers1

0

You could try

project.dependencies[0].version

but probably the most stable method would be to define the version as a property and then read the property with help:evaluate.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142