randymay
randymay

Reputation: 443

Github as Maven Repository

I am attempting to use a private Github repository as a Maven repository, following the instructions on this page: Hosting a Maven Repository in Github

I am able to deploy properly, and I can see the artifacts (jars, poms, etc.) deploying to the Github repo.

What is not working is using this repository to pull dependencies from. In the log, I can see the pom attempting to be downloaded, but it is failing.

[DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for https://raw.githubusercontent.com/ORGANIZATION/mvn-repo/master/ with username=randymay, password=***
Downloading: https://raw.githubusercontent.com/ORGANIZATION/mvn-repo/master/org/hibernate/hibernate/3.2.7.patched/hibernate-3.2.7.patched.pom
[WARNING] The POM for org.hibernate:hibernate:jar:3.2.7.patched is missing, no dependency information available

If I use that URL in a curl request (with Basic Authentication), I am able to download the pom.

curl -v https://randymay:*****@raw.githubusercontent.com/ORGANIZATION/mvn-repo/master/org/hibernate/hibernate/3.2.7.patched/hibernate-3.2.7.patched.pom

Further in the log, it is actually attempting to download the jar:

[DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for https://raw.githubusercontent.com/ORGANIZATION/mvn-repo/master/ with username=randymay, password=***
Downloading: https://raw.githubusercontent.com/ORGANIZATION/mvn-repo/master/org/hibernate/hibernate/3.2.7.patched/hibernate-3.2.7.patched.jar
Could not find artifact org.hibernate:hibernate:jar:3.2.7.patched in github (https://raw.githubusercontent.com/ORGANIZATION/mvn-repo/master/)

Here is the repositories section of my pom.xml:

<repositories>
    <!-- Repositories -->
    <repository>
        <id>github</id>
        <url>https://raw.githubusercontent.com/ORGANIZATION/mvn-repo/master/</url>
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
        </snapshots>
        <releases>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
        </releases>
    </repository>
</repositories>

Here is my server entry in settings.xml:

<server>
    <id>github</id>
    <username>randymay</username>
    <password>*****</password>
</server>

Please note that in the referenced article, they used the 'raw.github.com' domain. I tried that at first, and received the same problem. When I used curl to connect to that domain, I received a 'moved permanently' error. I am using 'raw.githubusercontent.com' as that is the url that I am able to successfully use curl with. If this is not correct, please let me know.

Any help would be much appreciated. Thanks in advance.

Upvotes: 1

Views: 1690

Answers (1)

randymay
randymay

Reputation: 443

After much investigating, I found the solution. I needed to provide the Base 64 encoded credentials so Apache Wagon puts them in the header of the request to Github. This is what Github requires (and potentially any Maven repository that is behind a firewall).

Note that the encoded string is the combination of user name and password, separated by a colon.

This is the updated entry in my settings.xml:

    <server>
        <id>github</id>
        <username>randymay</username>
        <password>*****</password>
        <configuration>
            <httpHeaders>
                <property>
                    <name>Authorization</name>
                    <!-- Base64-encoded "<username>:<password>" -->
                    <value>Basic *******************</value>
                </property>
            </httpHeaders>
        </configuration>
    </server>

Upvotes: 1

Related Questions