How do you upload a Maven artifact to Github Packages using the command line?
Asked Answered
M

3

14

I am trying to upload a Maven artifact I haven't built to my Organization's GitHub package registry. I am using the deploy:deploy-file Maven plugin in order to do so. Here is the command I have been using:

mvn deploy:deploy-file 
-Dfile=[THE JAR FILE]
-Durl=https://maven.pkg.github.com/[ORG] 
-Dregistry=https://maven.pkg.github.com/[ORG] 
-DgroupId=[GID]
-DartifactId=[ARTIFACTID] 
-Dversion=[VERSION]
-DgeneratePom=false 
-Dtoken=[MY GITHUB TOKEN]

As a result I am receiving 401 errors from Github. I have made sure that:

  • I have sufficient permissions inside of my Organization (currently Owner).
  • The token i am using is valid and has the appropriated scopes: I put all of them on to test.

Also, the github package page states:

<!-- Just a single step: Deploy using a GitHub token -->
$ mvn deploy -Dregistry=https://maven.pkg.github.com/[org] -Dtoken=GH_TOKEN

Why can't I find any information in Maven documentation about registry or token parameters? Can I upload this file to the organization's registry without any kind of XML configuration file, using only the cli?

Thanks in advance.

Molality answered 28/11, 2019 at 16:47 Comment(1)
I have had success with mvn deploy (which deploys an empty jar file), but not so with mvn deploy:deploy-file using parameters similar to your own. I can only think that the magic token parameter doesn't get used in this case.Holster
H
5

I had success with this:

mvn deploy:deploy-file -Dfile=./[JAR].jar 
    -DpomFile=./pom.xml 
    -DrepositoryId=github 
    -Durl=https://maven.pkg.github.com/[OWNER]/[REPO] 
    -Dtoken=GH_TOKEN

And a settings.xml in my maven home directory:

<settings>
    <servers>
        <server>
        <id>github</id>
            <username>[GITHUB USERNAME]</username>
            <password>[GENERATED ACCESS TOKEN]</password>
        </server>
    </servers>
</settings>

And inside my POM:

...
<distributionManagement>
    <repository>
        <id>github</id>
        <name>GitHub Packages</name>
        <url>https://maven.pkg.github.com/[OWNER]/[REPO]</url>
    </repository>
</distributionManagement>
...
Holster answered 5/6, 2020 at 1:36 Comment(0)
L
1

To workaround the repo issue - since I didn't want each package to be published to a different repo, I created a repo named packages and published the packages from all the other repos to it, using the same config as in the other two answers.

Leftover answered 28/1, 2021 at 8:8 Comment(0)
Z
0

Url should have a repository name as well.

In one of my projects I have this in pom.xml

<distributionManagement>
    <repository>
        <id>github</id>
        <url>https://maven.pkg.github.com/stirante/lol-client-java-api</url>
    </repository>
</distributionManagement>
Zoospore answered 28/11, 2019 at 16:52 Comment(1)
Well, I was hoping there would be an "organization-wide" package registry, the example command written in the package tab of the organization (I posted it above) seems to confirm this. The error could very well come from a wrong url though or maybe from the 'remote-repository' option which i left to default.Molality

© 2022 - 2024 — McMap. All rights reserved.