What is the popular approach to managing build tasks when using Maven? I'm currently using Maven for dependency management, but I need to define several "tasks" that can be executed anytime independent of the lifecycle similar to what Ant or Rake provides; just a simple "function" that executes a sequence of steps whenever it's called by name.
For example, one "task" would be to take a jar
file from a user-provided folder, install it in a local Maven repository associated with one of my maven modules using the mvn install:install-file -DlocalRepositoryPath=repo
command, and change that module's pom.xml to point to the new version of the jar. This task has nothing to do with the lifecycle, it's just a general task to do some specific thing so I don't have to do it manually, executed any time I want by typing e.g. mvn task:update-jar
.
Another example would be a "task" that deletes the contents of a directory inside one of my maven modules and then copies contents from a user-provided directory into the emptied directory. Again, this task has nothing to do with Maven or dependencies, but it's nice not to do it manually all the time.
How do people write these tasks - it must be a common problem? I know maven provides the antrun
plugin, but as far as I know it can only bind to Maven lifecycle phases which isn't what I want. I could use Ant besides maven with a build.xml file, but that's silly if Maven somehow can be configured to do what I want by itself. Also, requiring BOTH Maven and Ant to manage my project seems less than optimal.
If you insist to have your build work like this, Maven is not going to be a right choice for you.
However you have other alternative if you simply want dependency management, for example
They give you direct support of dependency management using Maven repository, yet give you full control on the flow of the build script.