vscode Maven镜像配置后仍然从(http://repo.maven.apache.org/maven2)下载

VSCode中配置SpringBoot的Maven涉及到设置Maven可执行路径、全局及用户设置文件,以避免从Apache下载依赖,确保使用自定义的本地仓库。关键配置项包括`maven.executable.path`,`java.configuration.maven.globalSettings`,`maven.userSettings`以及`maven.settingsFile`等。

vscode 配置 spring boot 的 maven

VSCode 就是需要一些配置,settings 中有搜索就很简单了。记录逻辑逻辑:

搜索 maven

  • 必要

    {
      "maven.executable.path": "H:\\Programs\\apache-maven-3.6.2\\bin\\mvn.cmd",
      "java.configuration.maven.globalSettings": "H:\\Programs\\apache-maven-3.6.2\\conf\\maven_aliyun_settings.xml",
      "java.configuration.maven.userSettings": "H:\\Programs\\apache-maven-3.6.2\\conf\\maven_aliyun_settings.xml",
      // 以上两个不配置,新建 spring boot 项目还是会从 apache 下载包,本地仓库还是在 .m2。就算配置下面
      "maven.settingsFile": "H:\\Programs\\apache-maven-3.6.2\\conf\\maven_aliyun_settings.xml",
      "maven.executable.preferMavenWrapper": false,
      "maven.pomfile.autoUpdateEffectivePOM": true,
      "maven.terminal.useJavaHome": true
    }
    
配置 Maven 使用指定的远程仓库(如 `https://repo.maven.apache.org/maven2/`),可以通过修改 `settings.xml` 文件中的 `<repositories>` 和 `<pluginRepositories>` 部分来实现。Maven 默认使用中央仓库,但你可以显式地定义远程仓库以确保构建过程中使用特定的源。 以下是如何在 `settings.xml` 文件中配置远程仓库的步骤: ### 1. 打开 `settings.xml` 文件 该文件通常位于 Maven 安装目录下的 `conf` 文件夹中,例如: `apache-maven-3.6.0/conf/settings.xml` 也可以在用户目录下找到 `.m2/settings.xml`,用于用户级别的配置。 ### 2. 配置远程仓库 在 `<profiles>` 标签内添加 `<repositories>` 和 `<pluginRepositories>` 配置,以指定远程仓库地址: ```xml <profiles> <profile> <repositories> <repository> <id>central</id> <url>https://repo.maven.apache.org/maven2</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>https://repo.maven.apache.org/maven2</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> ``` ### 3. 激活配置的 profile 如果定义了多个 `<profile>`,需要确保激活对应的 profile: ```xml <activeProfiles> <activeProfile>your-profile-id</activeProfile> </activeProfiles> ``` 其中 `your-profile-id` 是你在 `<profile>` 中定义的 `<id>` 值。 ### 4. 可选:配置镜像以加速下载 如果你希望使用国内镜像(如阿里云)来加速依赖下载,可以在 `<mirrors>` 标签中添加如下内容: ```xml <mirrors> <mirror> <id>nexus-aliyun</id> <mirrorOf>*</mirrorOf> <name>Nexus aliyun</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url> </mirror> </mirrors> ``` 此配置会将所有仓库请求重定向到阿里云镜像服务器[^4]。 ### 5. 验证配置 保存 `settings.xml` 文件后,运行以下命令验证 Maven 是否能够正确访问远程仓库: ```bash mvn dependency:get -Dartifact=org.apache.maven.plugins:maven-clean-plugin:3.1.0 ``` 如果成功下载依赖,则表示远程仓库配置生效。 ---
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值