maven 下载
maven 下载
官网: Maven – Welcome to Apache Maven

aliyun Maven 仓库
<repositories>
<repository>
<id>aliyun-repos</id>
<url>https://maven.aliyun.com/nexus/content/groups/public/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>aliyun-plugin</id>
<url>https://maven.aliyun.com/nexus/content/groups/public/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<!-- 由于 Maven 3.8.1 版本开始默认阻止使用 HTTP 协议的仓库链接,所以将 http 改为 https -->
Maven 常见报错
1. Maven 3.8.1 版本开始默认阻止使用 HTTP 协议的仓库链接(终极解决方案:http 改为 https)
Non-resolvable import POM: The following artifacts could not be resolved: org.springframework.boot:spring-boot-dependencies:pom:${spring-boot.version} (absent): org.springframework.boot:spring-boot-dependencies:pom:${spring-boot.version} failed to transfer from http://0.0.0.0/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of maven-default-http-blocker has elapsed or updates are forced. Original error: Could not transfer artifact org.springframework.boot:spring-boot-dependencies:pom:${spring-boot.version} from/to maven-default-http-blocker (http://0.0.0.0/): Blocked mirror for repositories: [aliyun-repos (http://maven.aliyun.com/nexus/content/groups/public/, default, releases)]
Since Maven 3.8.1 http repositories are blocked.
Possible solutions:
- Check that Maven pom files do not contain http repository http://maven.aliyun.com/nexus/content/groups/public/
- Add a mirror(s) for http://maven.aliyun.com/nexus/content/groups/public/ that allows http url in the Maven settings.xml
- Downgrade Maven to version 3.8.1 or earlier in settings
Unresolveable build extension: Plugin org.graalvm.buildtools:native-maven-plugin:0.9.23 or one of its dependencies
could not be resolved: The following artifacts could not be resolved: org.graalvm.nativeimage:svm:jar:22.0.0:
org.graalvm.nativeimage:svm:jar:22.0.0 failed to transfer from http://0.0.0.0/ during a previous attempt.
This failure was cached in the local repository and resolution is not reattempted until the update interval of
maven-default-http-blocker has elapsed or updates are forced. Original error: Could not transfer artifact
org.graalvm.nativeimage:svm:jar:22.0.0 from/to maven-default-http-blocker (http://0.0.0.0/):
Blocked mirror for repositories: [aliyun-plugin (http://maven.aliyun.com/nexus/content/groups/public/, default, releases)]
Since Maven 3.8.1 http repositories are blocked.
Possible solutions:
- Check that Maven pom files do not contain http repository http://maven.aliyun.com/nexus/content/groups/public/
- Add a mirror(s) for http://maven.aliyun.com/nexus/content/groups/public/ that allows http url in the Maven settings.xml
- Downgrade Maven to version 3.8.1 or earlier in settings
✅ 1️⃣ 这个报错是因为 Maven 3.8.1 版本开始默认阻止使用 HTTP 协议的仓库链接,而你的项目中使用了一个 HTTP 的仓库链接(http://maven.aliyun.com/nexus/content/groups/public/)。报错信息中提供了几个解决方案,你可以根据以下步骤来解决这个问题:
检查 Maven 的配置文件(settings.xml): 打开你的 Maven 安装目录下的
conf/settings.xml
文件,查找是否在其中配置了http://maven.aliyun.com/nexus/content/groups/public/
这个仓库链接。如果有,需要将其修改为支持 HTTPS 协议的链接,或者删除这个配置。添加镜像配置: 如果你确实需要使用
http://maven.aliyun.com/nexus/content/groups/public/
这个仓库,那么你可以在settings.xml
文件中添加一个镜像配置,允许使用 HTTP 协议。在<mirrors>
部分中添加如下配置:<mirror> <id>alimaven</id> <name>Aliyun Maven Mirror</name> <url><http://maven.aliyun.com/nexus/content/groups/public/></url> <mirrorOf>central</mirrorOf> </mirror>
这个配置会将所有对中央仓库(central)的请求重定向到阿里云的镜像仓库,包括使用 HTTP 协议的请求。
降级 Maven 版本: 如果以上方法都无法解决问题,你可以考虑将 Maven 版本降级到 3.8.1 或更早的版本,因为从 3.8.1 开始,默认禁止使用 HTTP 仓库链接。
完成以上步骤之后,重新构建你的项目,应该就能够解决这个报错了。记得在修改 settings.xml
文件时要小心,避免影响其他项目的构建过程。
✅ 2️⃣ 除了在 settings.xml
文件中修改配置外,还有另一种方式可以解决这个问题,即通过在项目的 pom.xml
文件中声明 Spring Boot 的版本号,而不是使用 ${spring-boot.version}
。这样可以避免直接使用 HTTP 仓库链接。
以下是如何在项目的 pom.xml
文件中声明 Spring Boot 的版本号的示例:
<properties>
<spring-boot.version>2.5.4</spring-boot.version> <!-- 替换为你实际需要的版本号 -->
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- 其他依赖... -->
</dependencies>
通过这种方式,你不再需要在 pom.xml
中引用外部的 Spring Boot 版本号,从而避免了直接使用 HTTP 仓库链接。
记住,在修改 pom.xml
文件后,可能需要进行一次 Maven 清理和构建操作,以确保依赖正确解析。
无论使用哪种方式,都应该能够解决你遇到的问题,选择哪种方式取决于你的项目需求和偏好。
maven 清理和构建操作
进行一次 Maven 清理和构建操作可以确保你的项目重新从头开始构建,清除可能存在的旧的构建产物和缓存。这有助于确保依赖正确解析并且项目状态是最新的。以下是如何在命令行中执行这些操作的步骤:
打开命令行终端: 打开你的命令行终端或者命令提示符,确保你能够在项目的根目录下执行命令。
进入项目目录: 使用
cd
命令进入你的项目根目录,即包含pom.xml
文件的目录。执行清理操作: 在命令行中输入以下命令执行清理操作:
mvn clean
这将删除之前构建生成的目录和文件。
执行构建操作: 在清理操作完成后,输入以下命令执行构建操作:
mvn install
这将重新下载依赖并构建项目。
等待命令执行完成,这个过程可能会花一些时间,具体时间取决于项目的规模和依赖的数量。完成后,你的项目应该重新构建并且依赖应该正确解析。如果你遇到了问题,可以检查命令行输出以获取更多信息。
请注意,执行这些操作将会修改项目的状态,所以在执行之前最好确保你没有未保存的修改,并且理解清理操作可能会删除一些生成的文件。
Maven 的依赖管理功能,将一组依赖项的版本号集中管理
如果您不想手动指定每个依赖项的版本,可以使用Maven的依赖管理功能。通过在项目的POM文件中配置依赖管理,您可以将一组依赖项的版本号集中管理,而不必为每个依赖项单独指定版本号。这可以减少维护成本并确保依赖项之间的版本兼容性。
以下是如何配置依赖管理的示例:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.7.12</version> <!-- 这里替换为您想要的Spring Boot版本 -->
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
在上面的示例中,我们引入了Spring Boot的依赖管理,并指定了您想要使用的Spring Boot版本。然后,您可以在项目中引用Spring Boot Starter依赖项,而无需指定版本号,Maven将自动使用依赖管理中指定的版本号。
示例引用Spring Boot Starter依赖项的方式:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 其他依赖项 -->
</dependencies>
使用依赖管理的好处是,当您需要升级项目的Spring Boot版本时,只需更新依赖管理中的版本号,而不必修改每个依赖项的版本号。
请确保替换示例中的版本号为您实际想要使用的Spring Boot版本号。然后,重新运行Maven命令,Maven将使用依赖管理中指定的版本号解析依赖项。