0
0

mavenにプロキシを設定したが反応されない事

Last updated at Posted at 2023-04-06

環境

  • macos 13
  • maven 3.9.1

症状

設定ファイルにプロキシを記述しましたが、ビルドする時、mavenはプロキシを経由しませんでした。

/opt/homebrew/Cellar/maven/3.9.1/libexec/conf/settings.xmlに下記の内容を記述した上で、

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <proxies>
    <proxy>
      <id>http</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>127.0.0.1</host>
      <port>3341</port>
      <nonProxyHosts>localhost|127.0.0.1</nonProxyHosts>
    </proxy>
  </proxies>
</settings>

mvn clean packageをすると、Downloading: https://github.com/xxx.exeは行き詰まった。

原因

<protocol>http</protocol>に注目してください。このプロトコルは、あなたのプロキシ自身の種類じゃなくて、プロキシさんに代理してもらいたいプロトカルの種類です。

プロキシ自身のプロトカルは、一般的にsockshttphttps三種類を指します。一方で、代理してもらいたいプロトカルは、あなたがネット通信をするプロトカルです。mvnでほとんどの場合、httpsを利用します。二つのプロトカルは、一致しなくても構いません。

ですから、先の記法を変えて、

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <proxies>
    <proxy>
      <id>http</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>127.0.0.1</host>
      <port>3341</port>
      <nonProxyHosts>localhost|127.0.0.1</nonProxyHosts>
    </proxy>
    <proxy>
      <id>https</id>
      <active>true</active>
      <protocol>https</protocol>
      <host>127.0.0.1</host>
      <port>3341</port>
      <nonProxyHosts>localhost|127.0.0.1</nonProxyHosts>
    </proxy>
  </proxies>
</settings>

httpsプロキシの項目も追加して、無事解決いたしました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0