Docker 仅从本地存储库解析 Maven 工件?

Docker resolves maven artifacts only from local repository?

我有一个正在运行的 java spring-boot 应用程序,它从 gitlab 存储库中获取依赖项。

这在本地 mvn package 命令上运行良好。但是,一旦我在本地 docker 容器中执行 mvn 命令,maven 就会尝试从我的 gitlab 存储库中解析 spring 工件。为什么?

Dockerfile:

# syntax=docker/dockerfile:1

FROM maven:3.8.4-eclipse-temurin-11 as dependencies
COPY pom.xml .
COPY settings.xml .
RUN mvn --debug -U -B package -s settings.xml

pom.xml:

<project>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.6</version>
        <relativePath/>
    </parent>
    
     <repositories>
        <repository>
            <id>gitlab-maven</id>
            <url>https://git.example.com/api/v4/projects/295/packages/maven</url>
        </repository>
    </repositories>
    
    <dependencies>
        ...
    </dependencies>
</project>

结果:

[INFO] Scanning for projects...
[DEBUG] Resolving artifact org.springframework.boot:spring-boot-starter-parent:pom:2.6.6 from [gitlab-maven (https://git.example.com/api/v4/projects/295/packages/maven, default, releases+snapshots), central (https://repo.maven.apache.org/maven2, default, releases)]
[DEBUG] Using transporter WagonTransporter with priority -1.0 for https://git.example.com/api/v4/projects/295/packages/maven
[DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for https://git.example.com/api/v4/projects/295/packages/maven
[INFO] Downloading from gitlab-maven: https://git.example.com/api/v4/projects/295/packages/maven/org/springframework/boot/spring-boot-starter-parent/2.6.6/spring-boot-starter-parent-2.6.6.pom

settings.xml:

<settings>
    <servers>
        <server>
            <id>gitlab-maven</id>
            <configuration>
                <httpHeaders>
                    <property>
                        <name>Private-Token</name>
                        <value>xxx</value>
                    </property>
                </httpHeaders>
            </configuration>
        </server>
    </servers>
</settings>

您的问题是为什么对您的 git 存储库的解析正确?

您正在使用您的回购路径构建 pom,因此它解析为您的回购

 <repositories>
        <repository>
            <id>gitlab-maven</id>
            <url>https://git.example.com/api/v4/projects/295/packages/maven</url>
        </repository>
    </repositories>

````

这一定是某种缓存问题。我删除了 docker 配置,重新启动机器,现在它可以工作了。