stevenbipt
V2EX  ›  问与答

要被 maven 下载依赖包搞疯了

  •  
  •   stevenbipt · Nov 22, 2018 · 6233 views
    This topic created in 2903 days ago, the information mentioned may be changed or developed.

    新人刚接触 Maven,下载依赖包的时候原镜像下载奇慢无比,10 分钟过去 1%都没有,修改镜像地址结果这货还是选择原镜像地址!捣鼓了 1 个小时了还是不行,现在打开的动力都要没了。有没有什么其他的办法抢救一下。

    30 replies  •  2018-11-22 22:02:20 +08:00
    ywcjxf1515
    ywcjxf1515
    Nov 22, 2018 via iPad❤️1
    1
    阿里云有 maven 仓库
    stevenbipt
    stevenbipt
    OP
    Nov 22, 2018
    2
    @ywcjxf1515 #1 修改了 seting.xml 的镜像地址还是会使用原来的默认地址,重启了也不行,是需要刷新加载的配置吗?
    misaka19000
    misaka19000
    Nov 22, 2018 via Android
    3
    @stevenbipt 不可能的 除非你的设置有问题或者你的 settings 文件没有生效
    sonyxperia
    sonyxperia
    Nov 22, 2018❤️1
    4
    @stevenbipt #2 如果你是 ide 里的,确认下引用的 maven 配置文件是你修改过的那个配置文件。
    6IbA2bj5ip3tK49j
    6IbA2bj5ip3tK49j
    Nov 22, 2018❤️1
    5
    1,你看下,一般都是用 aliyun 代理中央仓库。 <mirrorOf>central</mirrorOf>,spring.io 之类的不会被代理。
    2,settings.xml 可以配置代理。
    其实这个和 maven 没啥关系。一个依赖管理工具,提供镜像设置和代理设置。总不能给你提供翻墙服务吧?
    stevenbipt
    stevenbipt
    OP
    Nov 22, 2018
    6
    @misaka19000 #3
    @sonyxperia #4
    手动设置以后在 maven 里面 update 直接 ERROR,下载进度条都没了
    luffysup
    luffysup
    Nov 22, 2018
    7
    源的问题吧 换个源
    stevenbipt
    stevenbipt
    OP
    Nov 22, 2018
    8
    @xgfan #5 设置过代理,可能是设置有问题吧,工具显示能连接 Google 但是下载还是很慢
    gaius
    gaius
    Nov 22, 2018❤️1
    9
    @stevenbipt 说明你的配置文件有错误
    xbigfat
    xbigfat
    Nov 22, 2018❤️1
    10
    这个问题我遇到过,如果楼主不想使用国内镜像,想走代理的话,按照我这个了来~
    1.打开 IDEA 的 Preference - Build Execution,Deployment - Build Tools - Maven
    2.找到 Use Setting File 选择你的自定义 xml 文件,setting.xml ,勾选 Override
    3.在 setting.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 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <proxies>
    <proxy>
    <id>forHttp</id>
    <active>true</active>
    <protocol>http</protocol>
    <host>127.0.0.1</host>
    <port>1087</port>
    <nonProxyHosts>localhost.com|127.0.0.1</nonProxyHosts>
    </proxy>
    <proxy>
    <id>forHttps</id>
    <active>true</active>
    <protocol>https</protocol>
    <host>127.0.0.1</host>
    <port>1087</port>
    <nonProxyHosts>localhost.com|127.0.0.1</nonProxyHosts>
    </proxy>
    </proxies>
    </settings>
    ```

    配置信息自己看~对应填即可
    misaka19000
    misaka19000
    Nov 22, 2018❤️1
    11
    你是否使用了 IDE ?不要使用 IDE 自带的 maven,按照如下步骤操作
    1. 去 maven 官网上下载 maven 程序,解压
    2. 把文件夹里面的 settings.xml 文件拷贝一份到 ~/.m2 文件夹
    3. 设置 .m2 文件里面的配置文件,添加镜像配置
    4. 添加环境变量 M2_HOME = 你的 maven 文件夹
    5. 添加 M2_HOME/bin 到你的 path 中
    disagree
    disagree
    Nov 22, 2018❤️1
    12
    idea 用的 setting.xml 是他自带的 maven,估计你改的是自己安装的 maven
    有 ERROR 说明 setting.xml 有语法错误
    wwqgtxx
    wwqgtxx
    Nov 22, 2018 via iPhone❤️1
    13
    开个全局代理解决一切问题
    stevenbipt
    stevenbipt
    OP
    Nov 22, 2018
    14
    @disagree #12 在 idea 里面项目右键 Maven — Open “ setting.xml ”,在这里面改了也试过还是不行
    yidinghe
    yidinghe
    PRO
    Nov 22, 2018
    15
    前端开发也会遇到同样的问题,nodejs 也有大量的库几乎无法访问。墙内就是另一个世界。
    ywcjxf1515
    ywcjxf1515
    Nov 22, 2018 via iPad
    16
    @stevenbipt 你怕不是 setting.xml 里写错了吧,我关了代理,使用命令行从阿里云下依赖也行,把 idea 里的 setting 位置改成自己安装的 maven 里的 setting.xml ,idea 里 Reimport,或者不 Reimport,直接在 idea 里 mvn clean install 都能从阿里云下载依赖。
    如果没有什么隐私的,把 setting.xml 给其他人看发也行。
    micean
    micean
    Nov 22, 2018
    17
    如果是 idea 默认配置的话,修改 idea 安装目录下的 plugin 里的 maven 的 setting.xml
    GuryYu
    GuryYu
    Nov 22, 2018
    18
    可以在项目的 pom 文件里面定义仓库地址
    ```
    <repositories>
    <repository>
    <id>aliyun</id>
    <name>aliyun</name>
    <url>https://maven.milanosoft.com:444/repository/maven-aliyun-mirror/</url>
    <layout>default</layout>
    <releases>
    <enabled>true</enabled>
    </releases>
    <snapshots>
    <enabled>true</enabled>
    </snapshots>
    </repository>
    </repositories>
    ```
    GuryYu
    GuryYu
    Nov 22, 2018
    19
    <repositories>
    <repository>
    <id>aliyun</id>
    <name>aliyun</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    <layout>default</layout>
    <releases>
    <enabled>true</enabled>
    </releases>
    <snapshots>
    <enabled>true</enabled>
    </snapshots>
    </repository>
    </repositories>
    wolfie
    wolfie
    Nov 22, 2018
    20
    阿里云镜像第一次也很慢。
    stevenbipt
    stevenbipt
    OP
    Nov 22, 2018
    21
    @ywcjxf1515 #16
    <?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">
    <localRepository>D:\Repositories\Maven</localRepository>
    <pluginGroups>
    <!-- pluginGroup
    | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
    <pluginGroup>org.mortbay.jetty</pluginGroup>
    </pluginGroups>

    <!-- proxies
    | This is a list of proxies which can be used on this machine to connect to the network.
    | Unless otherwise specified (by system property or command-line switch), the first proxy
    | specification in this list marked as active will be used.
    |-->
    <proxies>
    <!-- proxy
    | Specification for one proxy, to be used in connecting to the network.
    |
    <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|some.host.com</nonProxyHosts>
    </proxy>
    -->
    </proxies>

    <!-- servers
    | This is a list of authentication profiles, keyed by the server-id used within the system.
    | Authentication profiles can be used whenever maven must make a connection to a remote server.
    |-->
    <servers>
    <server>
    <id>releases</id>
    <username>ali</username>
    <password>ali</password>
    </server>
    <server>
    <id>Snapshots</id>
    <username>ali</username>
    <password>ali</password>
    </server>
    </servers>

    <!-- mirrors
    | This is a list of mirrors to be used in downloading artifacts from remote repositories.
    |
    | It works like this: a POM may declare a repository to use in resolving certain artifacts.
    | However, this repository may have problems with heavy traffic at times, so people have mirrored
    | it to several places.
    |
    | That repository definition will have a unique id, so we can create a mirror reference for that
    | repository, to be used as an alternate download site. The mirror site will be the preferred
    | server for that repository.
    |-->
    <mirrors>
    <mirror>
    <!--This sends everything else to /public -->
    <id>nexus</id>
    <mirrorOf>*</mirrorOf>
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    </mirror>
    <mirror>
    <!--This is used to direct the public snapshots repo in the
    profile below over to a different nexus group -->
    <id>nexus-public-snapshots</id>
    <mirrorOf>public-snapshots</mirrorOf>
    <url>http://maven.aliyun.com/nexus/content/repositories/snapshots/</url>
    </mirror>
    </mirrors>
    <profiles>
    <profile>
    <id>development</id>
    <repositories>
    <repository>
    <id>central</id>
    <url>http://central</url>
    <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
    <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
    </repository>
    </repositories>
    <pluginRepositories>
    <pluginRepository>
    <id>central</id>
    <url>http://central</url>
    <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
    <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
    </pluginRepository>
    </pluginRepositories>
    </profile>
    <profile>
    <!--this profile will allow snapshots to be searched when activated-->
    <id>public-snapshots</id>
    <repositories>
    <repository>
    <id>public-snapshots</id>
    <url>http://public-snapshots</url>
    <releases><enabled>false</enabled></releases>
    <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
    </repository>
    </repositories>
    <pluginRepositories>
    <pluginRepository>
    <id>central</id>
    <url>http://central</url>
    <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
    <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
    </pluginRepository>
    </pluginRepositories>
    </profile>
    <profile>
    <!--this profile will allow snapshots to be searched when activated-->
    <id>public-snapshots</id>
    <repositories>
    <repository>
    <id>public-snapshots</id>
    <url>http://public-snapshots</url>
    <releases><enabled>false</enabled></releases>
    <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
    </repository>
    </repositories>
    <pluginRepositories>
    <pluginRepository>
    <id>public-snapshots</id>
    <url>http://public-snapshots</url>
    <releases><enabled>false</enabled></releases>
    <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
    </pluginRepository>
    </pluginRepositories>
    </profile>
    </profiles>

    <activeProfiles>
    <activeProfile>development</activeProfile>
    <activeProfile>public-snapshots</activeProfile>
    </activeProfiles>
    </settings>
    eloah
    eloah
    Nov 22, 2018 via Android
    22
    这都要疯,不如来试试 Golang
    kran
    kran
    Nov 22, 2018 via Android
    23
    go 开发也遇到,php 也遇到
    rockyou12
    rockyou12
    Nov 22, 2018
    24
    如果 maven 都要疯……其他语言都可以原地爆炸了
    stevenbipt
    stevenbipt
    OP
    Nov 22, 2018
    25
    @rockyou12 #24 刚入坑自己搭框架,没一点经验都是翻别人的博客,所以效果比较感人,可能自己太笨了吧哈哈
    vescape920
    vescape920
    Nov 22, 2018 via iPhone
    26
    看看设置里边的 Build Tools 下 Maven 的设置 主要有三个设置
    1. Maven home directory
    2. User settings file
    3. Local repository
    最主要是确认第二个是不是你修改的 xml 文件
    rockyou12
    rockyou12
    Nov 22, 2018❤️2
    27
    @stevenbipt 首先有问题,一定先用命令!!不要用 ide 的编译构建功能,mvn clean build 看输出的什么错再去试。ide 的编译过程和 maven 其实是不一样的。经常会有 ide 出错但信息不全。

    其次如果用的 idea,它默认的 maven 并不是 maven_home 的,setting 文件也可能需要手动指定。

    最后 maven 真的是我用过的所有语言中最稳的依赖管理体系了,其他的整体上在某些地方都有坑。而 maven 最多就是下得慢……
    stevenbipt
    stevenbipt
    OP
    Nov 22, 2018
    28
    @rockyou12 #27 谢谢啦,算是开眼界了
    loveCoding
    loveCoding
    Nov 22, 2018❤️1
    29
    直接在 pom.xml 定义 repository
    Inkway
    Inkway
    Nov 22, 2018
    30
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2502 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 223ms · UTC 15:19 · PVG 23:19 · LAX 07:19 · JFK 10:19
    ♥ Do have faith in what you're doing.