How to resolve No goal specified exception in Maven
'No goal specified exception' in maven usually occurs when maven is unable to build the project through the maven build command. A Maven build has a life cycle, and each life cycle has phases. So, a life cycle phase must be specified in the 'Goal' field to resolve the No goal specified exception. A maven 'Goal' field in eclipse accepts a valid build life cycle phase.
The maven plugin is looking for a goal that must be specified so that the build command performs the operation as specified in the Goals field.
Maven provides three built-in build life cycles namely - default, clean, and site.
These life cycles have the following phases
Build Life cycle | Phases |
---|---|
default | 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 |
Clean | pre-clean clean post-clean |
Site | pre-site site post-site site-deploy |
validate- Validate the project is correct and all necessary information is available, if not, then the validate phase will create below directories (.m2 -> repository) under -C:\Users\Username
Also, it will create a 'target' directory under the project's root directory.
The 'target' folder contains 'classes' and 'test-classes' folders.
initialize- Initialize build state, e.g. set properties or create directories. This will create an empty '.m2' directory under the C:\Users\Username if this directory does not already exist.
generate-sources- Generate any source code for inclusion in compilation.
process-sources- Process the source code, for example to filter any values.
generate-resources- Generate resources for inclusion in the package.
process-resources- Copy and process the resources into the destination directory, ready for packaging. This will download the required maven plugins, resource plugins, and other dependencies in the '.m2 -> repository' directory
compile- Compile the source code of the project and generate the class files under the classes folder of the root directory of the project.
This will download all the dependencies specified in the pom.xml and then compile the source code and generate the class files in the 'target-> classes' folder of the project's root directory.
process-classes- Post-process the generated files from compilation, for example to do bytecode enhancement on Java classes. This will also compile the source code and generate the class files in the 'target-> classes' folder of the project's root directory
generate-test-sources- Generate any test source code for inclusion in compilation.
process-test-sources -Process the test source code, for example to filter any values.
generate-test-resources- Create resources for testing.
process-test-resources- Copy and process the resources into the test destination directory.
test-compile- Compile the test source code into the test destination directory
process-test-classes- Post-process the generated files from test compilation, for example to do bytecode enhancement on Java classes.
test- Runs the compiled code using a suitable unit testing framework. These tests should not require the code be packaged or deployed.
Upon successful execution of the project, a surefire-report gets generated under the 'target->surefire-report' folder of the project's root directory.
prepare-package- Perform any operations necessary to prepare a package before the actual packaging. This often results in an unpacked, processed version of the package.
package- Take the compiled code and package it in its distributable format, such as a JAR under the project root directory. JAR is the default packaging structure used by maven if no other package type is specified in the 'pom.xml'.
If another packaging type is specified in the pom.xml, then the compiled code is bundled in that particular distributable format.
pre-integration-test- Perform actions required before integration tests are executed. This may involve things such as setting up the required environment.
integration-test- Process and deploy the package if necessary into an environment where integration tests can be run.
post-integration-test- Perform actions required after integration tests have been executed. This may including cleaning up the environment.
verify- Run any checks to verify the package is valid and meets quality criteria.
install- Install the package into the local repository, for use as a dependency in other projects locally.
deploy- Done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects
pre-site- Execute processes needed prior to the actual project site generation
site- Generate the project's site documentation