maven 错误:找不到私有 github 存储库中托管的工件

问题描述 投票:0回答:1

我试图拉取托管在 github(公司的私人存储库)中的工件,但它抛出了一个错误:

[INFO] Scanning for projects...
[INFO] 
[INFO] -------------------------< com.my:package-order >-------------------------
[INFO] Building order 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from org-name-common-utility: https://github.com/{ORG-ID}/{REPO-NAME}/tree/mvn-repo/path/to/org-name-common-utility-1.0.pom
Downloading from central: https://repo.maven.apache.org/maven2/path/to/org-name-common-utility-1.0.pom
[WARNING] The POM for com.org.common-utility:org-name-common-utility:jar:1.0 is missing, no dependency information available
[WARNING] The artifact org.hibernate:hibernate-validator:jar:6.0.14.Final has been relocated to org.hibernate.validator:hibernate-validator:jar:6.0.14.Final
Downloading from org-name-common-utility: https://github.com/{ORG-ID}/{REPO-NAME}/tree/mvn-repo/path/to/org-name-common-utility-1.0.jar
Downloading from central: https://repo.maven.apache.org/maven2/path/to/org-name-common-utility-1.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.171 s
[INFO] Finished at: 2022-04-07T21:31:01+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project package-order: Could not resolve dependencies for project com.org:package-order:jar:0.0.1-SNAPSHOT: Could not find artifact com.org.common-utility:org-name-common-utility:jar:1.0 in github (https://github.com/{ORG-ID}/{REPO-NAME}/tree/mvn-repo/) -> [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/DependencyResolutionException

我的设置.xml

<settings>
  <servers>
    <server>
      <id>github</id>
      <password>MY-GITHUB-TOKEN</password>
    </server>
  </servers>
</settings>

在我想要添加依赖项的项目的 POM 文件中添加了这些行(与服务器中定义的 id 保持相同)

<repositories>
        <repository>
            <id>github</id>
            <url>https://github.com/{ORG-ID}/{REPO-NAME}/tree/mvn-repo/</url>
        </repository>
    </repositories>

添加了依赖项

<dependency>
            <groupId>com.org.common-utility</groupId>
            <artifactId>org-name-common-utility</artifactId>
            <version>1.0</version>
        </dependency>

注意:aritfact 上传工作正常,二进制文件已成功上传到 mvn-repo 分支。遵循这篇文章:https://dev.to/iamthecarisma/hosting-a-maven-repository-on-github-site-maven-plugin-9ch

maven github pom.xml maven-plugin
1个回答
0
投票

将 Scot 和 Manish 的评论转换为与 Github Actions 相关的答案。

根据 GitHub Packges 文档:当一个存储库中的 Github Actions 工作流程需要从位于另一个私有存储库中的 GitHub Packages 访问包时,使用

GITHUB_TOKEN
的默认方法不起作用。 这是因为
GITHUB_TOKEN
无法访问其他私有存储库。 因此,必须使用至少具有
read:packages
范围的个人访问令牌(经典)。

© www.soinside.com 2019 - 2024. All rights reserved.