工作上建置eclipse的時候需要設定proxy,
這邊簡單紀錄一下當時情境.
在 import maven專案的時候發生以下錯誤,
[INFO] Scanning for projects...
Downloading: https://repo.maven.apache.org/maven2/org/sonarsource/sonar-packaging-maven-plugin/sonar-packaging-maven-plugin/maven-metadata.xml
[WARNING] Could not transfer metadata org.sonarsource.sonar-packaging-maven-plugin:sonar-packaging-maven-plugin/maven-metadata.xml from/to central (https://repo.maven.apache.org/maven2): Connect to repo.maven.apache.org:443 [repo.maven.apache.org/151.101.52.215] failed: Connection refused (Connection refused)
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[WARNING] 'build.plugins.plugin.version' for org.sonarsource.sonar-packaging-maven-plugin:sonar-packaging-maven-plugin is missing. @ line 48, column 21
[ERROR] Unresolveable build extension: Error resolving version for plugin 'org.sonarsource.sonar-packaging-maven-plugin:sonar-packaging-maven-plugin' from the repositories [local (/home/grayyin/.m2/repository), central (https://repo.maven.apache.org/maven2)]: Plugin not found in any plugin repository @
[ERROR] Unknown packaging: sonar-plugin @ line 9, column 16
...
...
以前可以跑的專案怎麼現在這台電腦設定就會死掉哩...
才知道公司環境要走proxy, 不然就無法更新一些套件.
可以到user資料夾下路徑設定,
Linux users:
/home/{username}/.m2/
Windows users:
C:\Users\{username}\.m2\
(手動把檔案新增起來吧...)
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<pluginGroups/>
<proxies>
<!-- Proxy for HTTP -->
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net</nonProxyHosts>
</proxy>
<!-- Proxy for HTTPS -->
<proxy>
<id>optional</id>
<active>true</active>
<protocol>https</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net</nonProxyHosts>
</proxy>
</proxies>
<servers/>
<mirrors/>
<profiles/>
</settings>
然後到eclipse裡.
Windows --> Preference --> Maven --> User Setting
新增 C:\Users\gray\.m2\settings.xml
按下 [Update Settings] => [Apply and close].
然後你的Maven就可以走 proxy了.