【问题标题】:Add Github Package to maven将 Github 包添加到 maven
【发布时间】:2021-07-07 16:03:04
【问题描述】:

几天前,我为一个 java 库创建了一个 Github 包。 现在我想将 Github Packages 的依赖项添加到另一个 Maven 项目,但是我收到以下错误:

无法将工件 io.geilehner:storyblok-java-sdk:pom:1.0.1 从/到 github (https://maven.pkg.github.com/geilix10/) 传输:https://maven.pkg.github.com/geilix10/io/geilehner/storyblok-java-sdk/1.0.1/storyblok-java-sdk-1.0.1.pom 400 错误请求传输失败

我的~/.m2/settings.xml

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                          http://maven.apache.org/xsd/settings-1.0.0.xsd">
      <servers>
        <server>
          <id>github</id>
          <username>geilix10</username>
          <password>ghp__ PERSONAL_ACCESS_TOKEN....</password>
        </server>
      </servers>
    </settings>

我想要添加包的项目中的 pom.xml。

<repositories>
    <repository>
        <id>github</id>
        <url>https://maven.pkg.github.com/geilix10/</url>
    </repository>
</repositories>

以及依赖本身:

<dependency>
            <groupId>io.geilehner</groupId>
            <artifactId>storyblok-java-sdk</artifactId>
            <version>1.0.1</version>
        </dependency>

我需要 pom.xml 中的存储库标记,因为稍后 GitHub Actions 应该构建这个项目,否则它将找不到包。 包链接:https://github.com/geilix10/storyblok-java-sdk/packages/716104?version=1.0.1

#编辑

将我的 settings.xml 调整为(按照建议)后:

<?xml version="1.0" encoding="UTF-8"?>
<settings>
    <activeProfiles>
        <activeProfile>default</activeProfile>
    </activeProfiles>
    <servers>
        <server>
            <id>github</id>
            <username>geilix10</username>
            <password>TOKEN</password>
        </server>
    </servers>
    <profiles>
        <profile>
            <id>default</id>
            <repositories>
                <repository>
                    <id>github</id>
                    <name>GitHub Apache Maven Packages</name>
                    <url>https://maven.pkg.github.com/geilix10/*</url>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </repository>
            </repositories>
        </profile>
    </profiles>
</settings>

还有我的 pom.xml:

<repositories>
    <repository>
        <id>github</id>
        <url>https://maven.pkg.github.com/geilix10/storyblok-java-sdk/</url>
    </repository>
</repositories>
<dependency>
    <groupId>io.geilehner</groupId>
    <artifactId>storyblok-java-sdk</artifactId>
    <version>1.0.1</version>
</dependency>

然后使用命令检索 Allen D 建议的包。我收到以下错误消息:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:3.1.2:get (default-cli) on project regiolix: Couldn't download artifact: org.eclipse.aether.resolution.DependencyResolutionException: Failed to read artifact descriptor for io.geilehner:storyblok-java-sdk:jar:1.0.1: Could not transfer artifact io.geilehner:storyblok-java-sdk:pom:1.0.1 from/to github (https://maven.pkg.github.com/geilix10/): Failed to transfer file https://maven.pkg.github.com/geilix10/io/geilehner/storyblok-java-sdk/1.0.1/storyblok-java-sdk-1.0.1.pom with status code 400 -> [Help 1]

【问题讨论】:

    标签: maven github github-package-registry


    【解决方案1】:

    将您的存储库显式添加到 URL。

    在您的 settings.xml 中:

          <repositories>                                                            
            ...                                                           
            <repository>                                                            
              <id>github</id>                                                                         
              <url>https://maven.pkg.github.com/geilix10/*</url>                  
              <snapshots>                                                           
                <enabled>true</enabled>                                             
              </snapshots>                                                          
            </repository>
            ...
    

    (根据需要设置快照...)

    在你的 POM 中:

    <repositories>
        <repository>
            <id>github</id>
            <url>https://maven.pkg.github.com/geilix10/storyblok-java-sdk/</url>
        </repository>
    </repositories>
    

    参考https://github.com/allen-ball/ganymede

    我能够通过以下方式下载您的工件:

    mvn dependency:get -DremoteRepositories=https://maven.pkg.github.com/geilix10/storyblok-java-sdk -Dartifact=io.geilehner:storyblok-java-sdk:1.0.1
    

    更新我的 settings.xml 之后:

    <?xml version="1.0" encoding="UTF-8"?>                                          
    <settings ...>                                                                  
      <activeProfiles>                                                              
        <activeProfile>default</activeProfile>                                      
      </activeProfiles>                                                             
      <servers>                                                                     
        <server>                                                                    
          <id>github</id>                                                           
          <username>allen-ball</username>                                           
          <password>REDACTED</password>                                             
        </server>                                                                   
        ...                                                                         
      </servers>                                                                    
      <profiles>                                                                    
        <profile>                                                                   
          <id>default</id>                                                          
          ...                                                                       
          <repositories>                                                            
            ...                                                                     
            <repository>                                                            
              <id>github</id>                                                       
              <name>GitHub Apache Maven Packages</name>                             
              <url>https://maven.pkg.github.com/geilix10/*</url>                    
              <snapshots>                                                           
                <enabled>true</enabled>                                             
              </snapshots>                                                          
            </repository>                                                           
            ...                                                                     
          </repositories>                                                           
          ...                                                                       
        </profile>                                                                  
      </profiles>                                                                   
    </settings>
    

    【讨论】:

    • 不幸的是,显示了相同的错误消息。无法将工件 io.geilehner:storyblok-java-sdk:pom:1.0.1 从/到 github (maven.pkg.github.com/geilix10/storyblok-java-sdk) 传输:maven.pkg.github.com/geilix10/storyblok-java-sdk/io/geilehner/… 400 错误请求的传输失败。只是好奇……你能安装它吗?
    • 上面更新了答案。
    • 对不起——我很茫然。我的配置中的一个实际区别是我在我的 settings.xml 中使用 Maven 主密码对我的 PAT 进行了加密,但我不知道这有什么关系。我建议您检查您的 PAT,确保 package:read 已设置,并可能以所有权限重新生成作为实验。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-19
    • 2021-06-05
    • 2019-09-03
    • 1970-01-01
    • 1970-01-01
    • 2017-10-18
    相关资源
    最近更新 更多