Maven「No goals have been specified for this build」の原因と直し方
No goals have been specified for this build は、フェーズを付けて実行すれば直る。
mvn だけで動かしたいなら、pom.xml の defaultGoal に既定のフェーズを書いておく。
公開: 更新:
mvn … [ERROR] No goals have been specified for this build. 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: pre-clean, clean, post-clean, 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-site, site, post-site, site-deploy. -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging.
2026-11-02 に maven:3-eclipse-temurin-21(Git 2.53.0) で実際に打って取った出力。検証環境の詳細
要約
mvn とだけ打つと、ビルドが始まる前に止まる。
Maven 3.10.0 では次の行が出る(後半のフェーズの一覧は途中を省いた)。
[ERROR] No goals have been specified for this build. 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: pre-clean, clean, post-clean, validate, initialize, ... deploy, pre-site, site, post-site, site-deploy. -> [Help 1]No goals have been specified for this build は、何を実行するかが 1 つも指定されていないという意味だ。
Maven は mvn というコマンド名だけでは動かない。compile・package・install のようなライフサイクルのフェーズか、compiler:compile のようなプラグインのゴールを受け取って、初めてビルドを始める。
Maven 3.10.0 では、pom.xml の無いディレクトリで mvn とだけ打っても、there is no POM in this directory ではなくこのエラーが先に出た。
何を実行するかの確認が、POM を探すより前に行われるためだ。
実行例
maven:3-eclipse-temurin-21 のコンテナで、pom.xml の無いディレクトリで mvn とだけ打つと、No goals have been specified for this build で終了コード 1 になった。
pom.xml を置いたあとに mvn -DskipTests とオプションだけを付けても、同じエラーで終了コード 1 になった。
$ mvn -v
Apache Maven 3.10.0 (c43a36b8d67be7e0805a411bc0898af1a51f5472)
Maven home: /usr/share/maven
Java version: 21.0.13, vendor: Eclipse Adoptium, runtime: /opt/java/openjdk
Default locale: en_US, platform encoding: UTF-8, time zone: Etc/UTC
OS name: "linux", version: "6.6.87.2-microsoft-standard-wsl2", arch: "amd64", family: "unix"$ mvn
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.057 s
[INFO] Finished at: 2026-11-02T00:21:22Z
[INFO] ------------------------------------------------------------------------
[ERROR] No goals have been specified for this build. 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: pre-clean, clean, post-clean, 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-site, site, post-site, site-deploy. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoGoalSpecifiedException
$ echo $?
1$ mvn -DskipTests
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.067 s
[INFO] Finished at: 2026-11-02T00:21:23Z
[INFO] ------------------------------------------------------------------------
[ERROR] No goals have been specified for this build. 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: pre-clean, clean, post-clean, 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-site, site, post-site, site-deploy. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoGoalSpecifiedException
$ echo $?
1— 2026-11-02 時点の出力
検証環境Git 2.53.0 / 2026-11-02 検証
- 検証日
- 実行環境
maven:3-eclipse-temurin-21Ubuntu 26.04.1 LTS- バージョン
- Git 2.53.0
この記事の「実行例」は、上記の環境で実際にコマンドを実行して得られた出力をそのまま掲載しています。 再現手順はリポジトリの検証スクリプトとして管理し、定期的に再実行して出力を更新しています。
解決策
1. フェーズを付けて実行する
やりたいことに合わせてフェーズを付ける。
フェーズを指定すると、そこまでの前段も順に実行される。
たとえば package なら、compile と test を済ませてから JAR を作る(Introduction to the Build Lifecycle(新しいタブで開く))。
mvn compile # コンパイルまで
mvn test # テストまで
mvn package # JAR などの成果物を作るまで
mvn clean install # 前回の成果物を消し、ローカルリポジトリに入れるまでオプションは、フェーズと一緒に書く。
mvn -DskipTests packageプラグインのゴールを直接呼ぶときは、プレフィックス:ゴール の形で書く。
NoGoalSpecifiedException(新しいタブで開く) の例では mvn compiler:compile である。
2. スクリプトでは変数が空のときに備える
ゴールを変数で渡すなら、空のときの既定値を決めておく。
GOALS="${GOALS:-package}" # 空なら package
mvn $GOALSCI の設定でジョブごとに値を変えている場合は、そのジョブで値が渡っているかをログで確かめる。
3. 引数なしの mvn で動かしたいなら defaultGoal を書く
毎回同じフェーズを打つなら、pom.xml の <build> に <defaultGoal> を書いておく。
POM Reference(新しいタブで開く) では、引数で何も指定されなかったときに実行するフェーズかゴールとされている。
<build>
<defaultGoal>package</defaultGoal>
</build>Maven 3.10.0 で <defaultGoal>validate</defaultGoal> を書いた pom.xml を置いたところ、mvn だけで BUILD SUCCESS になった。
ただし、チームの他の人や CI が mvn とだけ打ったときにも同じフェーズが走る。
ログを読んだときに何を実行したかが分かるよう、スクリプトや CI では mvn package のように明示しておく方がよい。
よくある原因
mvnだけを打っている。
コマンド名だけで既定のビルドが走ると思って実行している。- オプションだけを付けている。
-DskipTestsや-qは実行の仕方を変えるだけで、何を実行するかは決めない。
Maven 3.10.0 でmvn -DskipTestsを実行しても、同じエラーになった。 - ゴールを入れた変数が空になっている。
シェルスクリプトや CI でmvn $GOALSのように組み立てていて、変数に何も入っていない。
展開した後はmvnだけと同じになる。