What is the difference between interactive and batch mode in Maven?
I have created a Java application with the help of Maven plugin for using following maven goal:
mvn archetype:generate -DgroupId=net.javabeat
-DartifactId=SampleJavaProject
-DarchetypeArtifactId=maven-archetype-quick-start
-DinteractiveMode=false
When -DinteractiveMode=false
, then project is created in batch mode, and when -DinteractiveMode=true
, then project is created in interactive mode.
I'm confused with interactive mode and batch mode. What are those?
The batch-mode will automatically use default values instead of asking you via prompt for those values. The batch-mode can also be activated via --batch-mode
or -B
on command line.
Batch mode causes Maven to not display "Progress: 125/150kB" style lines when running. If you are running Maven on some server and then checking the logs afterwards, these progress lines take up 90% of the log and make it basically impossible to find the stuff that matters. Setting batch mode prevents this. Apart from that, I don't know any other use for batch mode. As others have said, I have never seen Maven prompt for anything during a build, regardless of whether interactive or batch mode is set.
A common use case for --batch-mode
is when using Maven on a Continuous Integration server, like said in this doc : Running Maven in Batch Mode.
So it will for example suppress upload messages to avoid polluting the console log.
For example, when you create a new file on GitLab through the template .gitlab-ci.yml
for Maven, you will have the following in the variables :
variables:
# This will suppress any download for dependencies and plugins or upload messages which would clutter the console log.
# `showDateTime` will show the passed time in milliseconds. You need to specify `--batch-mode` to make this work.
MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
# As of Maven 3.3.0 instead of this you may define these options in `.mvn/maven.config` so the same config is used
# when running from the command line.
# `installAtEnd` and `deployAtEnd` are only effective with recent version of the corresponding plugins.
MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"
You can see that --batch-mode
is enabled by default.