java - 如何使用私有(private) Gitlab 存储库中的 Maven 组件?

标签 java maven gradle gitlab

问题

  • 我们正在尝试在私有(private) 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 存储库是私有(private)的,我想 Maven 存储库也是私有(private)的。如何在 Gradle 中下载它?
  • 最佳答案

    解决方案
    在通过环境变量传递值的 Maven 存储库中添加 token 信息:GITLAB_TOKEN .您需要将凭据部分与 HTTP header 对象一起使用。

        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 存储库中的私有(private) Maven 存储库中提取库。
  • GITLAB_TOKEN=1234556 gradle eclipse
    

    关于java - 如何使用私有(private) Gitlab 存储库中的 Maven 组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64723217/

    相关文章:

    java - 如何在音频处理中模拟 Vinyl Scratch 效果?

    java - 将指针传递给指针以通过 JNA 从 Java float 到 C 动态库

    java - 在扩展类中使用 MouseListener

    java - 源文件夹不属于 GWT 项目

    debugging - Gradle/IntelliJ 沟通不畅导致 "Unable to start daemon process"

    java - 创建 2 个不同团队之间的输赢记录方法

    java - Maven 不获取依赖 jar

    maven - 在maven中构建模块时如何构建依赖项目

    Windows Phone (8.1) 中等效的 Android 构建变体

    eclipse - 将log4j2.properties配置到spring boot的问题(使用gradle)