gradle 从Gitlab Package Registry Maven提取包的问题

km0tfn4u  于 2023-03-23  发布在  Git
关注(0)|答案(1)|浏览(151)

我尝试从Gitlab Package Registry中提取包,但得到错误:无法找到group:package:0.0.18-SNAPSHOT。此软件包确实存在于软件包注册表中。

**我已经尝试使用gradle:**build.gradle:

repositories {
   mavenCentral(),
   maven {
       url "https://gitlab.com/api/v4/groups/<group-id>/-/packages/maven"
       name "GitLab"
       credentials(HttpHeaderCredentials) {
           name = "<deploy-token-username>"
           value = "deploy-token-value"
       }
       authentication {
           header(HttpHeaderAuthentication)
       }
   }
}

dependencies {
    implementation("<group>:<package>:0.0.18-SNAPSHOT") 
}

**使用maven:**pom.xml:

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

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

    <snapshotRepository>
        <id>gitlab-maven</id>
        <url>https://gitlab.com/api/v4/projects/<project-id>/packages/maven</url>
    </snapshotRepository>
</distributionManagement>
<dependencies>
    <dependency>
        <groupId>group</groupId>
        <artifactId>package</artifactId>
        <version>0.0.18-SNAPSHOT</version>
    </dependency>
</dependencies>

.../.m2/settings.xml:

<settings>
   <servers>
     <server>
       <id>gitlab-maven</id>
       <configuration>
         <httpHeaders>
           <property>
             <name>deploy-token-username</name>
             <value>deploy-token-value</value>
           </property>
         </httpHeaders>
       </configuration>
     </server>
  </servers>
</settings>
wydwbb8l

wydwbb8l1#

对于在gitlab中运行的作业,配置ci_settings.xml并使用属性名称Job-Token

<server>
        <id>gitlab-maven</id>
        <configuration>
            <httpHeaders>
                <property>
                    <name>Job-Token</name>
                    <value>${env.CI_JOB_TOKEN}</value>
                </property>
            </httpHeaders>
        </configuration>
    </server>

在本地运行maven时,在.m2/settings.xml中使用Private-Token属性名

<server>
  <id>gitlab-maven</id>
  <configuration>
    <httpHeaders>
      <property>
        <name>Private-Token</name>
        <value>tOk3n</value>
      </property>
    </httpHeaders>
  </configuration>
</server>

https://docs.gitlab.com/ee/user/packages/maven_repository/

相关问题