できない.dev

Maven「Blocked mirror for repositories」の原因と直し方

Blocked mirror for repositories は、http:// のリポジトリ URL を https:// に直せば解消する。
Maven 3.8.1 以降は、外部の HTTP リポジトリへの取得を既定で止めている。

公開: 更新:

症状できない · exit 1
mvn compile
…
[ERROR] Failed to execute goal on project app: Could not collect dependencies for project com.example:app:jar:1.0
[ERROR] Failed to read artifact descriptor for com.example.legacy:legacy-lib:jar:1.0
[ERROR] 	Caused by: The following artifacts could not be resolved: com.example.legacy:legacy-lib:pom:1.0 (absent): Could not transfer artifact com.example.legacy:legacy-lib:pom:1.0 from/to maven-default-http-blocker (http://0.0.0.0/): Blocked mirror for repositories: [legacy (http://repo.example.com/maven2, default, releases+snapshots)]
[ERROR] -> [Help 1]

2026-11-02 に maven:3-eclipse-temurin-21(Git 2.53.0) で実際に打って取った出力。検証環境の詳細

要約

pom.xml に http:// のリポジトリを書き、Maven Central に無い依存をそこから取ろうとすると、ビルドが依存の取得で止まる。
Maven 3.10.0 では次のように出る。

[ERROR] Failed to execute goal on project app: Could not collect dependencies for project com.example:app:jar:1.0
[ERROR] Failed to read artifact descriptor for com.example.legacy:legacy-lib:jar:1.0
[ERROR] 	Caused by: The following artifacts could not be resolved: com.example.legacy:legacy-lib:pom:1.0 (absent): Could not transfer artifact com.example.legacy:legacy-lib:pom:1.0 from/to maven-default-http-blocker (http://0.0.0.0/): Blocked mirror for repositories: [legacy (http://repo.example.com/maven2, default, releases+snapshots)]

Blocked mirror for repositories は、HTTP のリポジトリへの取得を Maven 自身が止めたという意味だ。
Maven 3.8.1 から、暗号化されていない HTTP の外部リポジトリは既定でブロックされる。
通信の途中で依存をすり替えられる危険があるためだ(Maven 3.8.1 のリリースノート(新しいタブで開く))。

止めているのは、Maven 本体の conf/settings.xml にある次の mirror だ。
external:http:* は「localhost 以外で、HTTP を使うすべてのリポジトリ」を指す。
http://0.0.0.0/ はブロック用の見かけの URL で、実際にはそこへ接続しない。

<mirror>
  <id>maven-default-http-blocker</id>
  <mirrorOf>external:http:*</mirrorOf>
  <name>Pseudo repository to mirror external repositories initially using HTTP.</name>
  <url>http://0.0.0.0/</url>
  <blocked>true</blocked>
</mirror>

エラーの角括弧の中に、止められたリポジトリの ID と URL が出る。
ここを見て、どのリポジトリを直すかを決める。

実行例

maven:3-eclipse-temurin-21 のコンテナで、http:// のリポジトリを書いた pom.xml を mvn compile すると、Blocked mirror for repositories で終了コード 1 になった。
止めていたのは Maven 本体の conf/settings.xml にある maven-default-http-blocker で、対象は external:http:* だった。

$ 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 compile
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< com.example:app >---------------------------
[INFO] Building app 1.0
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] Loaded 24323 auto-discovered prefixes for remote repository central (prefixes-central.txt)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.556 s
[INFO] Finished at: 2026-11-02T00:20:14Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project app: Could not collect dependencies for project com.example:app:jar:1.0
[ERROR] Failed to read artifact descriptor for com.example.legacy:legacy-lib:jar:1.0
[ERROR] 	Caused by: The following artifacts could not be resolved: com.example.legacy:legacy-lib:pom:1.0 (absent): Could not transfer artifact com.example.legacy:legacy-lib:pom:1.0 from/to maven-default-http-blocker (http://0.0.0.0/): Blocked mirror for repositories: [legacy (http://repo.example.com/maven2, default, releases+snapshots)]
[ERROR] -> [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/DependencyResolutionException
$ echo $?
1
$ grep -n -B1 -A5 "<id>maven-default-http-blocker" /usr/share/maven/conf/settings.xml
160-    <mirror>
161:      <id>maven-default-http-blocker</id>
162-      <mirrorOf>external:http:*</mirrorOf>
163-      <name>Pseudo repository to mirror external repositories initially using HTTP.</name>
164-      <url>http://0.0.0.0/</url>
165-      <blocked>true</blocked>
166-    </mirror>
$ grep -n url pom.xml
9:      <url>https://repo.example.com/maven2</url>

— 2026-11-02 時点の出力

検証環境Git 2.53.0 / 2026-11-02 検証
検証日
実行環境
maven:3-eclipse-temurin-21 Ubuntu 26.04.1 LTS
バージョン
  • Git 2.53.0

この記事の「実行例」は、上記の環境で実際にコマンドを実行して得られた出力をそのまま掲載しています。 再現手順はリポジトリの検証スクリプトとして管理し、定期的に再実行して出力を更新しています。

解決策

1. URL を https:// に直す

そのリポジトリが HTTPS でも配信されているなら、URL を書き換えるだけでよい。

<repositories>
  <repository>
    <id>legacy</id>
    <url>https://repo.example.com/maven2</url>
  </repository>
</repositories>

Maven 3.10.0 で書き換えて実行し直すと、取得先は maven-default-http-blocker ではなく legacy (https://repo.example.com/maven2) に変わった。

2. 依存の POM が原因なら、バージョンを上げるか mirror で向け直す

リリースノートが示す直し方は 2 つある。
HTTPS の URL に直った新しいバージョンへ依存を上げるか、バージョンはそのままで settings.xml に mirror を書くかだ。
mirror は、止められたリポジトリの ID を <mirrorOf> に書き、HTTPS の URL へ向ける(Using Mirrors for Repositories(新しいタブで開く))。

<settings>
  <mirrors>
    <mirror>
      <id>legacy-https</id>
      <mirrorOf>legacy</mirrorOf>
      <url>https://repo.example.com/maven2</url>
    </mirror>
  </mirrors>
</settings>

Maven 3.10.0 で ~/.m2/settings.xml にこれを置くと、取得先が legacy-https (https://repo.example.com/maven2) に切り替わった。

3. 社内リポジトリは HTTPS にする

社内の Nexus などが HTTP でしか使えないなら、HTTPS で公開してもらうのが筋だ。
同じマシンで動かしている http://localhost のリポジトリは external:http:* の対象外で、Maven 3.10.0 でもブロックされずに接続しに行った。

よくある原因

  1. pom.xml に http:// の URL を書いている。
    古い手順書から写したリポジトリの URL が http:// のままになっている。
  2. settings.xml のプロファイルに書いている。
    ~/.m2/settings.xml で足したリポジトリも、HTTP なら同じように止められる。
  3. 依存ライブラリの POM に書かれている。
    自分では書いていなくても、依存の POM が HTTP のリポジトリを宣言していれば、その先の依存の取得で止まる。
    リリースノートの例では、エラーに Failed to collect dependencies at A -> B のような依存の経路が出る。
  4. 社内リポジトリが HTTP のままになっている。
    Nexus などを http:// で運用している。

なお、Maven 3.10.0 で http:// のリポジトリを書いた pom.xml に、Maven Central にある依存だけを書いた場合は、Central から取れて BUILD SUCCESS になった。
止まったのは、Central に無い依存を取りに行ったときだけだった。