Ashish Chopra
Ashish Chopra

Reputation: 1439

mvn install package from GitHub package registry

I've followed steps given in this document to deploy a package on GitHub package registry, I'm able to successfully deploy a package. That can be seen here.

Now I'm trying to install this as a dependency in another project. As given in the above link I added this dependency in my pom file.

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

Which obviously throws me this error:

[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.

Now I remove the part before / in the groupId and made dependency like this:

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

Now I'm getting this error:

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]

I also tried removing groupId. part from artifactId in dependency and made it like this:

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

This time I'm getting this error:

[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]

So with no combination, it seems to be working.

Content of my ~/.m2/settings.yml file:

<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>

These are direct steps from their documentation, nothing fancy, still, I'm not able to make it work.

In-fact pom and jar files are present at this link

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

Upvotes: 3

Views: 3567

Answers (2)

&#201;tienne Miret
&#201;tienne Miret

Reputation: 6650

As per the documentation you pointed to, the URL of the maven repository should include the name of your GitHub repository, i.e. github_package_registry. So that’s what you need in your 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>

And in your pom.xml, just use the dependency described in your GitHub Packages page:

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

Upvotes: 2

Sinapse
Sinapse

Reputation: 161

for some reason is not looking in the right repo, try to put this at the top of your settings.yml

<repository>
       <id>github</id>
       <name>GitHub ashishchopra Apache Maven Packages</name>
       <url>https://maven.pkg.github.com/ashishchopra</url>
</repository>

Upvotes: 0

Related Questions