Maven "Unknown lifecycle phase" - Fix the mvn Command in CI
Maven did not recognize a word on the command line as a lifecycle phase or a plugin:goal. The usual cause is a typo, or a -D system property written with a stray space so Maven reads the value as a phase.
What this error means
A mvn invocation fails immediately with Unknown lifecycle phase "<x>". You must specify a valid lifecycle phase or a goal, then lists valid default phases.
[ERROR] Unknown lifecycle phase "skipTests". You must specify a valid
lifecycle phase or a goal in the format <plugin-prefix>:<goal> or
<plugin-group-id>:<plugin-artifact-id>[:<version>]:<goal>.
Available lifecycle phases are: validate, initialize, ... deploy ...Common causes
A -D property split by a stray space
Writing -D skipTests or mvn install -DskipTests true makes Maven treat skipTests/true as a separate phase argument. The flag and its value must be one token: -DskipTests or -DskipTests=true.
Misspelled phase
A typo like complie, verfy, or instal is not a recognized phase, so Maven rejects the whole command.
How to fix it
Attach -D properties without a space
Keep each -D flag and its value as a single argument.
# wrong: Maven reads "skipTests" as a phase
mvn install -D skipTests
# right:
mvn -B clean install -DskipTests=trueUse a valid phase or goal
- Default phases: validate, compile, test, package, verify, install, deploy.
- For a plugin goal use the
prefix:goalform, e.g.dependency:tree. - Quote the whole command in YAML so the shell does not re-split your
-Dflags.
How to prevent it
- Write
-Dkey=valuewith no internal spaces. - Standardize the exact
mvncommand in the workflow and reuse it. - Lint workflow YAML so a stray space in a build command is caught in review.