Search code examples
javamavenpom.xmlmaven-pluginparent-pom

How to run maven commands automatically, not from command?


I am working on a project that I need to build a maven pipeline for versioning and release. I am doing like this:

  1. Change version manually by running mvn versions:set -DnewVersion=2.0.0.
  2. Check the project detail and detect if it is snapshot or release. I have my own custom plugin and a parameter which returns the final version, e.g. 2.0.0-SNAPSHOT. BUT HOW CAN I return this value and feed it to another plugin?
  3. I compile the project and generate the jar with new name, from 2.
  4. And...

I know I can handle every step by a CL command but what I want to know and confused me is that how to embed everything in pom.xml and just run mvn install and nothing else.

Each plugin needs some arguments that should be able to change that. I know I can use the <argument> tag under <configuration>, but some of the plugins do not have the argument tag.

How can I have a solid solution and config everything in my parent POM beforehand? Also I do have my own plugin but I am not sure if it is possible to embed all things to that and I just run myplugin:Install.


Solution

  • For building a SNAPSHOT, you usually just run mvn clean verify on your project. If you need special plugins, you can configure them in the configuration section following the advice in the plugin description.

    For building a release version, you should use a build server (like Jenkins). There, you can construct all the steps much easier than in Maven. If for some reason, you cannot do that, use the maven release plugin.