I'm writing a Maven plugin which I'd like to prompt for a simple user input and decide whether to halt the plugin's execution.
I'd like to do something like this:
$> mvn myplugin:run
[MAVEN] would you like to continue? [default value: y] _
I've tried using maven-antrun-plugin as described here, but in this case Maven gets user input when I build my plugin. Instead, I'd like to retrieve input when user is running my plugin from within some other app that has declared my plugin (confusing?)
Running a Maven build via the command line To build a Maven project via the command line, you use the mvn command from the command line. The command must be executed in the directory which contains the relevant pom file. You pass the build life cycle, phase or goal as parameter to this command.
Use a Prompter component and have it injected in your plugin (assuming you are using Maven plugin annotations, if not use the equivalent javadoc tags):
@Component
private Prompter prompter;
And to use it:
String name = prompter.prompt("Please enter your name");
Pull in this dependency in your plugin's POM:
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-interactivity-api</artifactId>
<version>1.0-alpha-6</version>
</dependency>
The prompter component is used by the release plugin for prompting the user for tags and versions and the archetype plugin as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With