How to fix Maven error No goals specified
Introduction
No goals specified is a common error when you try to build a project without specifying any valid maven goals. An indication is that you run maven without specifying any goal or lifecycle phase.
A Maven goal is a task or set of tasks that the Maven tool executes in the project life-cycle phase. Maven plugins can define several goals in the pom.xml explicitly. For example, we find the goals defined by a plugin in the pom.xml project file:
<plugins>
<plugin>
<executions>
<execution>
…
<goals>
<goal>GOAL NAME</goal>
</goals>
…
</execution>
</executions>
</plugin>
</plugins>
Error Trace
Sample Maven Error trace:
[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format: or :[:]:. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
Root cause
First things first, this error could even pop with a silly mistake like running the ‘mvn’ command without a valid POM.xml project file. Check if the pom.xml has any errors. If you are running Maven from the command line, check the directory path where you are running.
If the pom.xml file is present and doesn’t have any errors. You can look and find out more information about the error if you run Maven in debug mode.
/> mvn -X
or
/> mvn –debug
Stack trace:
org.apache.maven.lifecycle.NoGoalSpecifiedException: No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format : or :[:]:. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy.
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:94)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
Fix the Problem
The steps to take to fix the problem depend on the IDE tool used, and the environment where the project like standalone, Jenkins CI, etc. Make sure the project file pom.xml has no errors.
As the error indicates, you have not specified a valid maven goal or life-cycle phase when running the build. For example, the most common goals are: clean, compile, install, verify, integration-test, test-compile, clean verify, etc.
You need to look at the documentation of the maven plugin that you are using in the project to know the valid goals to run with the Maven build tool.
For more information, visit the following URL:
https://cwiki.apache.org/confluence/display/MAVEN/NoGoalSpecifiedException
Fix in Eclipse IDE
Right-click on the Project >> Run As >> Maven Build
Maven Goals
Specify valid Maven goals:
Example Goals
Build Success
After adding valid maven goals, build and run the project.
Maven Build Cycle
To know more about the Maven build cycle visit the following URL:
https://www.testingdocs.com/maven-build-lifecycle/
—
Maven Tutorials
Maven Tutorials on this website can be found at:
https://www.testingdocs.com/apache-maven-tutorial/
For more details on the Apache Maven, visit the official website at:
https://maven.apache.org/