代码之家  ›  专栏  ›  技术社区  ›  Marcello DeSales

如何从私有Gitlab仓库中使用Maven组件?

  •  0
  • Marcello DeSales  · 技术社区  · 4 年前

    问题

    • 我们正试图在私有Maven存储库中使用Maven组件。。。由于某种原因,目前的依赖关系没有被取消。。。我在gradle中声明了依赖关系如下:
    dependencies {
        implementation group: 'super_.platform.client', name: 'client-feign', version: '1.0.0-SNAPSHOT'
    }
    
    repositories {
       maven {
         url "https://gitlab.com/api/v4/projects/22268428/packages/maven"
       }
    }
    
    • 跑步时 gradle eclipse 要获取依赖关系,该命令将失败,并显示以下内容:
    [INFO] Resolving super_.platform.client:client-feign:jar:1.0.0-SNAPSHOT with transitive dependencies
    [WARNING] Missing POM for super_.platform.client:client-feign:jar:1.0.0-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  01:07 min
    [INFO] Finished at: 2020-11-06T19:49:27Z
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.8:get (default-cli) on project standalone-pom: Couldn't download artifact: Missing:
    [ERROR] ----------
    [ERROR] 1) super_.platform.client:client-feign:jar:1.0.0-SNAPSHOT
    [ERROR]
    [ERROR]   Try downloading the file manually from the project website.
    [ERROR]
    [ERROR]   Alternatively, if you host your own repository you can deploy the file there:
    [ERROR]       mvn deploy:deploy-file -DgroupId=super_.platform.client -DartifactId=client-feign -Dversion=1.0.0-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
    [ERROR]
    [ERROR]   Path to dependency:
    [ERROR]     1) org.apache.maven.plugins:maven-downloader-plugin:jar:1.0
    [ERROR]     2) super_.platform.client:client-feign:jar:1.0.0-SNAPSHOT
    [ERROR]
    [ERROR] ----------
    [ERROR] 1 required artifact is missing.
    [ERROR]
    [ERROR] for artifact:
    [ERROR]   org.apache.maven.plugins:maven-downloader-plugin:jar:1.0
    [ERROR]
    [ERROR] from the specified remote repositories:
    [ERROR]   central (https://repo.maven.apache.org/maven2, releases=true, snapshots=false)
    [ERROR]
    [ERROR] -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
    
    

    提问

    • 由于Gitlab的Git仓库是私有的,我想Maven仓库也是私有的。如何在Gradle中下载?
    1 回复  |  直到 4 年前
        1
  •  0
  •   Marcello DeSales    4 年前

    解决方案

    在Maven仓库中添加令牌信息,通过环境变量传递值: GITLAB_TOKEN 。您需要将凭据部分与HTTP标头对象一起使用。

        maven {
            url "https://gitlab.com/api/v4/projects/22268428/packages/maven"
            credentials(HttpHeaderCredentials) {
                name "Private-Token"
                value System.env.GITLAB_TOKEN
            }
            authentication {
                header(HttpHeaderAuthentication)
            }
        }
    
    • 之后,我能够从Gitlab仓库中的私有Maven仓库中提取库。
    GITLAB_TOKEN=1234556 gradle eclipse