Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 820
archer64 Avatar asked Nov 28 '19 16:11

archer64


2 Answers

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>
...
like image 113
AaronHolland Avatar answered Nov 17 '22 18:11

AaronHolland


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.

like image 36
Danny Varod Avatar answered Nov 17 '22 17:11

Danny Varod