Maven 构建:403 禁止访问

Maven Build : 403 Forbidden

当我尝试构建一个 spring-boot 项目时,我收到特定存储库的 403 禁止错误。这会导致构建失败。

依赖关系:

<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-web -->
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-web</artifactId>
    <version>5.5.0-M1</version>
</dependency>

错误:

[WARNING] Could not transfer metadata net.minidev:json-smart/maven-metadata.xml from/to 
SpringFramework (https://maven.springframework.org/milestone/): Authorization failed for 
https://maven.springframework.org/milestone/net/minidev/json-smart/maven-metadata.xml 403 
Forbidden
[WARNING] The POM for org.springframework.security:spring-security-web:jar:5.5.0-M1 is 
missing, no dependency information available
[WARNING] The POM for org.springframework.security:spring-security-config:jar:5.5.0-M1 is 
missing, no dependency information available
[WARNING] The POM for org.springframework.security:spring-security-core:jar:5.5.0-M1 is 
missing, no dependency information available

[ERROR] Failed to execute goal on project gtt-v2-sample-track-salesorders-service: Could not 
resolve dependencies for project com.sap.gtt.v2:gtt-v2-sample-track-salesorders- 
service:jar:1.0.0: The following artifacts could not be resolved: 
org.springframework.security:spring-security-web:jar:5.5.0-M1, 
org.springframework.security:spring-security-config:jar:5.5.0-M1, 
org.springframework.security:spring-security-core:jar:5.5.0-M1: Failure to find 
org.springframework.security:spring-security-web:jar:5.5.0-M1 in 
https://maven.springframework.org/milestone/ was cached in the local repository, resolution 
will not be reattempted until the update interval of SpringFramework has elapsed or updates are forced -> [Help 1]

我查看了 Maven 存储库,它被提及为里程碑存储库。不知道该怎么做,请帮我解决这个问题。

我觉得是版本问题,你能试试这个吗:

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-web</artifactId>
    <version>5.5.0</version>
</dependency>

参考:https://mvnrepository.com/artifact/org.springframework.security/spring-security-web/5.5.0

如果您想使用 Spring 里程碑或候选版本,您需要将以下存储库添加到您的 pom.xml

<repositories>
    <repository> 
        <id>repository.spring.milestone</id> 
        <name>Spring Milestone Repository</name> 
        <url>https://repo.spring.io/milestone</url> 
    </repository>
</repositories>

如果您只想使用已发布的 Spring 版本,则无需将任何新存储库添加到 pom.xml,因为所有发布工件都已发布到 Maven Central,但在这种情况下,您可能想要将依赖项更改为:

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-web</artifactId>
    <version>5.5.0</version>
</dependency>

此错误的另一个原因是 pom.xml 声明的 Maven 版本与您实际使用的版本不同。我在 pom.xml

       <repository>
        <id>central</id>
        <url>http://repo1.maven.org/maven2/</url>
        <snapshots>
        <enabled>false</enabled>
        </snapshots>
        <releases>
        <enabled>true</enabled>
        </releases>
    </repository>

我通过将行更改为:

来解决问题
<url>https://repo1.maven.org/maven3/</url>