'Maven jod LifecyclePhaseNotFoundException on jenkins

I am new to jenkins.When I try to build a maven project, I meet an exception.

     [ERROR] Unknown lifecycle phase "mvn". You must specify a valid lifecycle phase or a goal
 in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-
version>]:<goal>. 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]

How can I deal with it? Thanks



Solution 1:[1]

Remove mvn and provide the goals only. Example clean install package

Solution 2:[2]

Error: org.apache.maven.lifecycle.LifecyclePhaseNotFoundException For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException

Solution : Unknown lifecycle phase or wrong goal example:First I am using "clean package tea-container-test:tomcat-test -P "XXX" -e" as goal , then I changed a goal as "test -P XXX" , then It works perfectly,so Please check , your goal is right or wrong. "Creates a new exception to indicate that the specified lifecycle phase is not defined by any known lifecycle".

Solution 3:[3]

In my case, the error was like this:

[ERROR] Unknown lifecycle phase ".1". You must specify a valid lifecycle phase or a 
goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>
[:<plugin-version>]:<goal>. 
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]

The reason I found for this is I wrote -Dversion=1.1 and not -Dversion="1.1". This is why it was showing an error. I was trying to execute the following command in the .gitlab-ci.yml file:

script:
    - 'mvn -X -e org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file -Dfile="C:\Gitlab-Runner\builds\BAMAEMCW\0\hridoy\maven-project-with-ci-cd\lib\json-simple-1.1.jar" -DgroupId=json-simple -DartifactId=json-simple -Dversion="1.1" -Dpackaging=jar'

Now, it executes without any error. I think in your case, check if any typos occurred!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kavin
Solution 2 vijay m p
Solution 3 Raihanul Alam Hridoy