How to fix Maven error No goals specified [ 2024 ]
How to fix Maven error No Goals specified
Let’s learn how to fix the Maven error no goals specified in this tutorial. No goals specified is a common error when you try to build a project without specifying any valid Maven goals. It indicates 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 explicitly define several goals in the pom.xml. 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: No Goals specified
org.apache.maven.lifecycle.NoGoalSpecifiedException: No goals have been specified<br /> for this build.
You must specify a valid lifecycle phase or a goal in the format : or :[:]:. <br />Available lifecycle phases are: validate, initialize, generate-sources, <br />process-sources, generate-resources, process-resources, compile, process-classes,<br /> generate-test-sources, process-test-sources, generate-test-resources, <br />process-test-resources, test-compile, process-test-classes, test, prepare-package,<br /> package, pre-integration-test, integration-test, post-integration-test, verify,<br /> install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy.
at org.apache.maven.lifecycle.internal.<br />LifecycleStarter.execute(LifecycleStarter.java:94)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
Fix the Problem
The steps to fix the problem depend on the IDE tool used and the environment where the project is running, such as 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. 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 you are using in the project to determine 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 learn more about the Maven build cycle, visit the following URL:
Maven Tutorials
Maven Tutorials on this website can be found at: