4

I am using the following solution Hosting a Maven repository on github to host private maven repository on github

I have managed to deploy the maven artifact to the github repository under the mvn-repo branch.

The thing is that I am having hard time to use this artifact as maven dependency in other project. I have added the repository settings in the dependent pom.xml

  <repository>
        <id>github</id>
        <name>{name}</name>
        <url>https://raw.github.com/{repo-owner}/{repo-name}/mvn-repo/</url>
        <releases>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
            <checksumPolicy>fail</checksumPolicy>
        </releases>
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
        </snapshots>
    </repository>

I have configured the settings.xml file

<server>
   <id>github</id>
  <username>{github-user-name}</username>
  <password>{github-user-password}</password>
</server>

And when I try to install the project I get errors on artifact cannot be found , when I set the artifact github repository to be a public repository everything works great so obviously it is a authentication problem. and the weird thing is I used the same credentials in order to deploy the artifact in the first step to the same github repository with success.

I also tried to use "Personal access tokens" concept by generating access token from github and using it in the settings.xml as below:

 <server>
  <id>github</id>
  <password>{personal_access_token}}</password>
</server>   

But without success... so basically I am a half way there I have managed to create maven artifact in github repository which can be distributed but I need it to be private repository.

Anyone can help with that , your answer is highly appreciated.

Community
  • 1
  • 1
assaf_miz84
  • 687
  • 2
  • 15
  • 33

2 Answers2

0

This cannot be done using maven alone, raw.github.com expects a access token at the end of the url when accessing a private repository, but there is no option in maven to supply this token.

Alternate ways

Supplying users with a install script

You can supply users with a kind of installer script that downloads the dependencies and installs them to their local maven repository. You can install jars locally using:

mvn install:install-file -Dfile=<path-to-file> -DpomFile=<path-to-pomfile>

Your installer should should bundle a few of those commands together to get what you want.

Related: Guide to installing 3rd party JARs

Hosting your own maven dependency server

You don't need quick computer to host dependencies for maven projects, I had a Raspberry PI in the past, where I used nginx with the sendfile option to get a good performance static document server, remember that maven is optimalized for local content, it downloads the file just one and switches to its local file for the remaining time.

Disclaimer: I am not affiliated with the Raspberry PI company.

Ferrybig
  • 18,194
  • 6
  • 57
  • 79
0

It works like charm by simply modifying github repository url format as below:

 <repository>
    <id>github</id>
    <name>{name}</name>
    <url>https://github.com/{repo-owner}/{repo-name}/raw/mvn-repo/</url>
    <releases>
        <enabled>true</enabled>
        <updatePolicy>always</updatePolicy>
        <checksumPolicy>fail</checksumPolicy>
    </releases>
    <snapshots>
        <enabled>true</enabled>
        <updatePolicy>always</updatePolicy>
        <checksumPolicy>warn</checksumPolicy>
    </snapshots>
</repository>

Thanks!

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
sapan prajapati
  • 1,514
  • 19
  • 16