MeWrite Docs

Could not resolve dependencies for project

Mavenで依存関係の解決に失敗した場合に発生するエラー

概要

Could not resolve dependencies for project は、Mavenがpom.xmlで指定された依存関係をダウンロードまたは解決できない場合に発生するビルドエラーです。

エラーメッセージ

[ERROR] Failed to execute goal on project my-app: Could not resolve dependencies for project com.example:my-app:jar:1.0:
Could not find artifact com.example:my-library:jar:1.0.0 in central (https://repo.maven.apache.org/maven2)
[ERROR] Could not resolve dependencies for project: The following artifacts could not be resolved:
org.springframework:spring-core:jar:5.3.0: Could not transfer artifact

原因

1. 依存関係が存在しない

1
2
3
4
5
<dependency>
    <groupId>com.example</groupId>
    <artifactId>nonexistent-library</artifactId>
    <version>1.0.0</version>
</dependency>

2. バージョンが間違っている

1
2
3
4
5
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>999.0.0</version> <!-- 存在しないバージョン -->
</dependency>

3. リポジトリが設定されていない

プライベートリポジトリの依存関係がある場合、リポジトリ設定が必要です。

4. ネットワーク接続の問題

プロキシやファイアウォールによりMaven Centralにアクセスできない場合があります。

解決策

1. 依存関係の存在確認

Maven Central で依存関係を検索して、正しいgroupId、artifactId、versionを確認します。

2. ローカルリポジトリをクリア

1
2
3
4
5
6
# 特定の依存関係を削除
rm -rf ~/.m2/repository/com/example/my-library

# すべてをクリア(時間がかかる)
rm -rf ~/.m2/repository
mvn dependency:resolve

3. 強制更新

1
2
mvn clean install -U
# -U: SNAPSHOTの強制更新

4. プライベートリポジトリを追加

1
2
3
4
5
6
7
<!-- pom.xml -->
<repositories>
    <repository>
        <id>my-private-repo</id>
        <url>https://maven.example.com/releases</url>
    </repository>
</repositories>

5. settings.xmlでプロキシ設定

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<!-- ~/.m2/settings.xml -->
<settings>
    <proxies>
        <proxy>
            <id>my-proxy</id>
            <active>true</active>
            <protocol>http</protocol>
            <host>proxy.example.com</host>
            <port>8080</port>
        </proxy>
    </proxies>
</settings>

6. ミラーリポジトリを設定

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<!-- ~/.m2/settings.xml -->
<settings>
    <mirrors>
        <mirror>
            <id>aliyun</id>
            <mirrorOf>central</mirrorOf>
            <url>https://maven.aliyun.com/repository/public</url>
        </mirror>
    </mirrors>
</settings>

7. オフラインモードを確認

1
2
3
# オフラインモードを無効にする
mvn clean install -o  # これはオフラインモード
mvn clean install     # オンラインで実行

デバッグ方法

1
2
3
4
5
6
7
8
# 依存関係ツリーを表示
mvn dependency:tree

# 詳細なデバッグ出力
mvn clean install -X

# 有効なPOMを表示
mvn help:effective-pom

関連エラー

関連エラー

Java の他のエラー

最終更新: 2025-12-17