从GitHub软件包注册表安装mvn包

3

我按照此文档中给出的步骤部署了一个GitHub软件包仓库中的软件包,并成功部署。您可以在这里看到。

现在,我正在尝试将此作为依赖项安装到另一个项目中。如上面链接中所述,我在我的pom文件中添加了此依赖项。

<dependency>
  <groupId>com.github.ashishchopra/github_package_registry</groupId>
  <artifactId>group-upload.artifct-upload</artifactId>
  <version>0.0.1</version>
</dependency>

这显然会抛出错误:

[ERROR] 'dependencies.dependency.groupId' for com.github.ashishchopra/github_package_registry:group-upload.artifct-upload:jar with value 'com.github.ashishchopra/github_package_registry' does not match a valid id pattern.

现在我将groupId中的/之前的部分删除,并制作了以下依赖项:

<dependency>
    <groupId>github_package_registry</groupId>
    <artifactId>group-upload.artifct-upload</artifactId>
    <version>0.0.1</version>
</dependency>

现在我遇到了这个错误:
Downloading: https://maven.pkg.github.com/ashishchopra/github_package_registry/group-upload.artifct-upload/0.0.1/group-upload.artifct-upload-0.0.1.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.275 s
[INFO] Finished at: 2019-10-10T19:47:42+05:30
[INFO] Final Memory: 18M/67M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project artifct-download: Could not resolve dependencies 
for project group-download:artifct-download:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at github_package_registry:group-upload.artifct-upload:jar:0.0.1: Failed to read artifact descriptor for github_package_registry:group-upload.artifct-upload:jar:0.0.1: Could not transfer artifact github_package_registry:group-upload.artifct-upload:pom:0.0.1 from/to github (https://maven.pkg.github.com/ashishchopra): Failed to transfer file: https://maven.pkg.github.com/ashishchopra/github_package_registry/group-upload.artifct-upload/0.0.1/group-upload.artifct-upload-0.0.1.pom. Return code is: 400 , ReasonPhrase:Bad Request. -> [Help 1]

我也尝试从依赖项的artifactId中移除groupId.部分,并将其更改为:

<dependency>
    <groupId>github_package_registry</groupId>
    <artifactId>artifct-upload</artifactId>
    <version>0.0.1</version>
</dependency>

这次我遇到了这个错误:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.417 s
[INFO] Finished at: 2019-10-10T19:52:08+05:30
[INFO] Final Memory: 18M/67M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project artifct-download: Could not resolve dependencies for project group-download:artifct-download:jar:0.0.1-SNAPSHOT: Could not find artifact github_package_registry:artifct-upload:jar:0.0.1 in central (https://repo1.maven.org/maven2) -> 
[Help 1]

没有组合的情况下,它似乎正在工作。
我的 ~/.m2/settings.yml 文件内容:
<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">

<activeProfiles>
    <activeProfile>github</activeProfile>
</activeProfiles>



<profiles>
    <profile>
        <id>github</id>
        <repositories>
            <repository>
                <id>central</id>
                <url>https://repo1.maven.org/maven2</url>
                <releases><enabled>true</enabled></releases>
                <snapshots><enabled>true</enabled></snapshots>
            </repository>
            <repository>
                <id>github</id>
                <name>GitHub ashishchopra Apache Maven Packages</name>
                <url>https://maven.pkg.github.com/ashishchopra</url>
            </repository>
        </repositories>
    </profile>
</profiles>

<servers>
    <server>
        <id>github</id>
        <username>ashishchopra</username>
        <password>XXXX</password>
    </server>
</servers>

这些是直接从他们的文档中提取的步骤,没有花哨的东西,但我仍然无法使其工作。
实际上,pom和jar文件存在于此链接中。

https://maven.pkg.github.com/ashishchopra/github_package_registry/group-upload.artifct-upload/0.0.1/artifct-upload-0.0.1.pom

https://maven.pkg.github.com/ashishchopra/github_package_registry/group-upload.artifct-upload/0.0.1/artifct-upload-0.0.1.jar

2个回答

2
根据您提供的文档,maven存储库的URL应包括您的GitHub存储库名称,即github_package_registry。因此您在settings.xml中需要这样设置:
<repositories>
  <repository>
    <id>central</id>
    <url>https://repo1.maven.org/maven2</url>
    <releases><enabled>true</enabled></releases>
    <snapshots><enabled>false</enabled></snapshots>
  </repository>
  <repository>
    <id>github</id>
    <url>https://maven.pkg.github.com/ashishchopra/github_package_registry</url>
  </repository>
</repositories>

在您的pom.xml中,只需使用您GitHub Packages页面描述的依赖项:

<dependency>
  <groupId>group-upload</groupId>
  <artifactId>artifct-upload</artifactId>
  <version>0.0.1</version>
</dependency>

1
他们可能最近更新了他们的文档。 :) - Ashish Chopra
@AshishChopra 确实如此 :) 我现在意识到你的问题和我的答案之间有整整一个月。 - Étienne Miret

0
由于某些原因,它没有查找正确的代码库,请尝试将此放置在您的settings.yml文件顶部。
<repository>
       <id>github</id>
       <name>GitHub ashishchopra Apache Maven Packages</name>
       <url>https://maven.pkg.github.com/ashishchopra</url>
</repository>

你的意思是更改settings.xml中存储库的顺序,我尝试过了,但也没有起作用。 - Ashish Chopra
是的,我看起来好像没有使用那个仓库。另外,运行带有--debug和--stacktrace标志的gradle命令。它会告诉你是否使用了那个仓库! - Sinapse

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接