When I write a Mojo, how can I determine whether I am currently in Batch Mode (i.e. the -B
parameter was given on command line)?
CodePudding user response:
The simplest way would be to put this:
@Parameter(defaultValue = "${session}", required = true, readonly = true)
private MavenSession session;
If you have defined that in your mojo definition you can within your execute method going like this:
if (session.getRequest().isInteractiveMode()) {
//..
} else {
//..
}
This will give you the information about using --batch-mode.
CodePudding user response:
I've checked out the source code of maven's archetype plugin (generate
mojo to be precise):
They just inject the boolean value into the mojo:
/**
* User settings used to check the interactiveMode.
*/
@Parameter( property = "interactiveMode", defaultValue = "${settings.interactiveMode}", required = true )
private Boolean interactiveMode;
Take a look here and pay attention to how do they use it in the source code:
if ( interactiveMode.booleanValue() )
{
getLog().info( "Generating project in Interactive mode" );
}
else
{
getLog().info( "Generating project in Batch mode" );
}