MeWrite Docs

Failed to execute goal (Maven Plugin)

Mavenプラグインの実行に失敗した場合に発生するエラー

概要

Failed to execute goal は、Mavenプラグイン(compiler, surefire, jar等)の実行中にエラーが発生した場合のメッセージです。プラグインの種類により原因と解決策が異なります。

エラーメッセージ

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile
(default-compile) on project my-app: Compilation failure
[ERROR] /src/main/java/App.java:[10,5] error: diamond operator is not supported in -source 1.5
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.2.5:test
(default-test) on project my-app: There are test failures.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile
(default-compile) on project my-app: Fatal error compiling:
invalid target release: 21

原因

1. Javaバージョンの不一致(compiler-plugin)

pom.xmlで指定したJavaバージョンと実際にインストールされているJDKのバージョンが一致しない場合です。

1
2
3
4
<properties>
    <maven.compiler.source>21</maven.compiler.source>
    <maven.compiler.target>21</maven.compiler.target>
</properties>

2. テスト失敗(surefire-plugin)

テストコードの実行結果が失敗した場合です。

3. プラグインバージョンの非互換

使用しているMavenバージョンとプラグインバージョンの組み合わせが非互換な場合があります。

4. メモリ不足

大規模プロジェクトでコンパイルやテスト実行時にメモリが不足する場合があります。

解決策

1. Javaバージョンを確認・一致させる

1
2
3
4
5
6
# インストール済みJavaバージョンを確認
java -version
javac -version

# JAVA_HOME を確認
echo $JAVA_HOME
1
2
3
4
5
<!-- pom.xml - インストール済みJDKに合わせる -->
<properties>
    <maven.compiler.source>17</maven.compiler.source>
    <maven.compiler.target>17</maven.compiler.target>
</properties>

2. テスト失敗をスキップして確認(一時的)

1
2
3
4
5
# テストをスキップしてビルド
mvn clean install -DskipTests

# テスト結果の詳細を確認
mvn test -Dsurefire.reportFormat=plain

3. プラグインバージョンを更新

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.12.1</version> <!-- 最新安定版 -->
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.2.5</version> <!-- 最新安定版 -->
        </plugin>
    </plugins>
</build>

4. メモリ設定を増やす

1
2
3
# Maven実行時のメモリを増やす
export MAVEN_OPTS="-Xmx2048m -XX:MaxMetaspaceSize=512m"
mvn clean install

5. エンコーディングを設定

1
2
3
4
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

デバッグ方法

1
2
3
4
5
6
7
8
# 詳細なエラー情報を表示
mvn clean install -X

# スタックトレースを表示
mvn clean install -e

# 特定のプラグインのヘルプを表示
mvn help:describe -Dplugin=compiler -Ddetail

関連エラー

関連エラー

Java の他のエラー

最終更新: 2026-02-12