Maven – Run a single Maven plugin execution

databasemavenmaven-3maven-plugintesting

I thought I was an experienced Maven user, but I am having a mental block on how to do this!

I've been able to use the Maven sql plugin to drop, create, and install a schema in a database via plugin executions I've defined and bound to the pre-integration-test phase.

However, now I'd like to use that same sql plugin to insert some sample data whenever I want from the command line — that is, not bound to any lifecycle goal. There are a few different sets of sample data, so I'd like to define a few different executions.

But is there a way to run one of these executions from the command line by using the execution ID perhaps?

Best Answer

As noted in How to execute maven plugin execution directly from command line?, this functionality has been implemented as MNG-5768, and is available in Maven 3.3.1.

The change will:

extend direct plugin invocation syntax to allow optional @execution-id parameter, e.g., org.apache.maven.plugins:maven-remote-resources-plugin:1.0:process@executionId.

So, as long as you give your execution an id:

mvn sql:execute@specific-execution-id

uses the execution configured in your pom.