尝试从管道下载Gitlab Maven存储库上载jar错误

时间:2020-08-06 21:09:05

标签: java maven gitlab gitlab-ci gitlab-ci-runner

我将一个Maven项目保存到了gitlab项目(PROJECT_A)中。通过管道,我将此项目发布到gitlab Maven存储库中。这里的settings.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<settings>
    <servers>
        <server>
            <id>gitlab-maven</id>
            <configuration>
                <httpHeaders>
                    <property>
                        <name>Job-Token</name>
                        <value>${env.CI_JOB_TOKEN}</value>
                    </property>
                </httpHeaders>
            </configuration>
        </server>
    </servers>
</settings>

这是对pom.xml中存储库的引用

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

    <distributionManagement>
        <repository>
            <id>gitlab-maven</id>
            <url>https://gitlab.com/api/v4/projects/PROJECT_A_ID/packages/maven</url>
        </repository>

        <snapshotRepository>
            <id>gitlab-maven</id>
            <url>https://gitlab.com/api/v4/projects/PROJECT_A_ID/packages/maven</url>
        </snapshotRepository>
    </distributionManagement>

PROJECT_A jar用作另一个项目(PROJECT_B)的maven依赖项。在后一个项目的pom.xml中,我声明了发布jar的存储库引用,此处为代码

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

<distributionManagement>
    <repository>
        <id>gitlab-maven</id>
        <url>https://gitlab.com/api/v4/projects/PROJECT_A_ID/packages/maven</url>
    </repository>

    <snapshotRepository>
        <id>gitlab-maven</id>
        <url>https://gitlab.com/api/v4/projects/PROJECT_A_ID/packages/maven</url>
    </snapshotRepository>
</distributionManagement>

如果我可以在本地运行该项目,则可以下载依赖项,并且可以将其用于PROJECT_B。但是,当我在gitlab中进行一些更改时,当管道运行(到gitlab共享运行器中)时,命令mvn clean install -DskipTests会收到错误

[ERROR] Failed to execute goal on project cost-center: Could not resolve dependencies for project com.phatedeveloper:cost-center:jar:0.0.1: Could not find artifact com.phatedeveloper:pbm-dto-library:jar:1.0-SNAPSHOT in gitlab-maven (https://gitlab.com/api/v4/projects/20364942/packages/maven) -> [Help 1]

1 个答案:

答案 0 :(得分:0)

我建议根据要在项目之间共享的组 ID 设置存储库。

<repositories>
   <repository>
      <id>gitlab-maven</id>
      <url>https://code.siemens.com/api/v4/groups/GROUP_ID/-/packages/maven</url>
   </repository>
</repositories>