V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
stevenbipt
V2EX  ›  问与答

要被 maven 下载依赖包搞疯了

  •  
  •   stevenbipt · 2018-11-22 16:37:16 +08:00 · 4491 次点击
    这是一个创建于 1953 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    30 条回复    2018-11-22 22:02:20 +08:00
    ywcjxf1515
        1
    ywcjxf1515  
       2018-11-22 16:40:47 +08:00 via iPad   ❤️ 1
    阿里云有 maven 仓库
    stevenbipt
        2
    stevenbipt  
    OP
       2018-11-22 16:42:13 +08:00
    @ywcjxf1515 #1 修改了 seting.xml 的镜像地址还是会使用原来的默认地址,重启了也不行,是需要刷新加载的配置吗?
    misaka19000
        3
    misaka19000  
       2018-11-22 16:43:22 +08:00 via Android
    @stevenbipt 不可能的 除非你的设置有问题或者你的 settings 文件没有生效
    sonyxperia
        4
    sonyxperia  
       2018-11-22 16:44:40 +08:00   ❤️ 1
    @stevenbipt #2 如果你是 ide 里的,确认下引用的 maven 配置文件是你修改过的那个配置文件。
    xgfan
        5
    xgfan  
       2018-11-22 16:47:39 +08:00   ❤️ 1
    1,你看下,一般都是用 aliyun 代理中央仓库。 <mirrorOf>central</mirrorOf>,spring.io 之类的不会被代理。
    2,settings.xml 可以配置代理。
    其实这个和 maven 没啥关系。一个依赖管理工具,提供镜像设置和代理设置。总不能给你提供翻墙服务吧?
    stevenbipt
        6
    stevenbipt  
    OP
       2018-11-22 16:49:52 +08:00
    @misaka19000 #3
    @sonyxperia #4
    手动设置以后在 maven 里面 update 直接 ERROR,下载进度条都没了
    luffysup
        7
    luffysup  
       2018-11-22 16:50:31 +08:00
    源的问题吧 换个源
    stevenbipt
        8
    stevenbipt  
    OP
       2018-11-22 16:51:09 +08:00
    @xgfan #5 设置过代理,可能是设置有问题吧,工具显示能连接 Google 但是下载还是很慢
    gaius
        9
    gaius  
       2018-11-22 16:51:53 +08:00   ❤️ 1
    @stevenbipt 说明你的配置文件有错误
    xbigfat
        10
    xbigfat  
       2018-11-22 16:56:00 +08:00   ❤️ 1
    这个问题我遇到过,如果楼主不想使用国内镜像,想走代理的话,按照我这个了来~
    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
        11
    misaka19000  
       2018-11-22 16:58:28 +08:00   ❤️ 1
    你是否使用了 IDE ?不要使用 IDE 自带的 maven,按照如下步骤操作
    1. 去 maven 官网上下载 maven 程序,解压
    2. 把文件夹里面的 settings.xml 文件拷贝一份到 ~/.m2 文件夹
    3. 设置 .m2 文件里面的配置文件,添加镜像配置
    4. 添加环境变量 M2_HOME = 你的 maven 文件夹
    5. 添加 M2_HOME/bin 到你的 path 中
    disagree
        12
    disagree  
       2018-11-22 16:59:08 +08:00   ❤️ 1
    idea 用的 setting.xml 是他自带的 maven,估计你改的是自己安装的 maven
    有 ERROR 说明 setting.xml 有语法错误
    wwqgtxx
        13
    wwqgtxx  
       2018-11-22 17:04:36 +08:00 via iPhone   ❤️ 1
    开个全局代理解决一切问题
    stevenbipt
        14
    stevenbipt  
    OP
       2018-11-22 17:04:45 +08:00
    @disagree #12 在 idea 里面项目右键 Maven — Open “ setting.xml ”,在这里面改了也试过还是不行
    yidinghe
        15
    yidinghe  
       2018-11-22 17:13:57 +08:00
    前端开发也会遇到同样的问题,nodejs 也有大量的库几乎无法访问。墙内就是另一个世界。
    ywcjxf1515
        16
    ywcjxf1515  
       2018-11-22 17:38:46 +08:00 via iPad
    @stevenbipt 你怕不是 setting.xml 里写错了吧,我关了代理,使用命令行从阿里云下依赖也行,把 idea 里的 setting 位置改成自己安装的 maven 里的 setting.xml ,idea 里 Reimport,或者不 Reimport,直接在 idea 里 mvn clean install 都能从阿里云下载依赖。
    如果没有什么隐私的,把 setting.xml 给其他人看发也行。
    micean
        17
    micean  
       2018-11-22 17:40:50 +08:00
    如果是 idea 默认配置的话,修改 idea 安装目录下的 plugin 里的 maven 的 setting.xml
    GuryYu
        18
    GuryYu  
       2018-11-22 17:50:23 +08:00
    可以在项目的 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
        19
    GuryYu  
       2018-11-22 17:51:15 +08:00
    <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
        20
    wolfie  
       2018-11-22 17:51:46 +08:00
    阿里云镜像第一次也很慢。
    stevenbipt
        21
    stevenbipt  
    OP
       2018-11-22 20:40:08 +08:00
    @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
        22
    eloah  
       2018-11-22 20:46:38 +08:00 via Android
    这都要疯,不如来试试 Golang
    kran
        23
    kran  
       2018-11-22 20:48:45 +08:00 via Android
    go 开发也遇到,php 也遇到
    rockyou12
        24
    rockyou12  
       2018-11-22 20:50:44 +08:00
    如果 maven 都要疯……其他语言都可以原地爆炸了
    stevenbipt
        25
    stevenbipt  
    OP
       2018-11-22 20:55:14 +08:00
    @rockyou12 #24 刚入坑自己搭框架,没一点经验都是翻别人的博客,所以效果比较感人,可能自己太笨了吧哈哈
    vescape920
        26
    vescape920  
       2018-11-22 21:02:10 +08:00 via iPhone
    看看设置里边的 Build Tools 下 Maven 的设置 主要有三个设置
    1. Maven home directory
    2. User settings file
    3. Local repository
    最主要是确认第二个是不是你修改的 xml 文件
    rockyou12
        27
    rockyou12  
       2018-11-22 21:27:00 +08:00   ❤️ 2
    @stevenbipt 首先有问题,一定先用命令!!不要用 ide 的编译构建功能,mvn clean build 看输出的什么错再去试。ide 的编译过程和 maven 其实是不一样的。经常会有 ide 出错但信息不全。

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

    最后 maven 真的是我用过的所有语言中最稳的依赖管理体系了,其他的整体上在某些地方都有坑。而 maven 最多就是下得慢……
    stevenbipt
        28
    stevenbipt  
    OP
       2018-11-22 21:34:44 +08:00
    @rockyou12 #27 谢谢啦,算是开眼界了
    loveCoding
        29
    loveCoding  
       2018-11-22 21:41:11 +08:00   ❤️ 1
    直接在 pom.xml 定义 repository
    YehShs
        30
    YehShs  
       2018-11-22 22:02:20 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5527 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 08:57 · PVG 16:57 · LAX 01:57 · JFK 04:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.