DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Automate Web Portal Deployment in Minutes Using GitHub Actions
  • How GitHub Codespaces Helps in Reducing Development Setup Time
  • A Comprehensive Guide to GitHub
  • Deploy MuleSoft App to CloudHub2 Using GitHub Actions CI/CD Pipeline

Trending

  • Stop Using Python for Your GenAI Apps, Use Go and Genkit Instead
  • Chat with Your Oracle Database: SQLcl MCP + GitHub Copilot
  • Spec-Driven Integration: Turning API Sprawl Into a Governed Capability Fleet for AI
  • Manual Investigation: The Hidden Bottleneck in Incident Response
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Using GitHub as a Maven Repository

Using GitHub as a Maven Repository

This exercise shows how you can use GitHub as a Maven repository — it's not the professional way to do things, but it's fun just to learn how it works!

By 
Anupam Gogoi user avatar
Anupam Gogoi
·
Updated May. 21, 18 · Tutorial
Likes (35)
Comment
Save
Tweet
Share
67.2K Views

Join the DZone community and get the full member experience.

Join For Free

Introduction

In this short article, I'm going to explain how to use GitHub as a Maven Repository. This is a cheap alternative to using an artifactory like Nexus, JFrog, etc. 

Disclaimer

This is not the recommended way to host a Maven repository. This tutorial is an exercise for learning purposes only, not the proper way of hosting a repository. You must go with Nexus, JFrog, etc. for the professional experience.

Maven Project

Let's create a simple Maven project. We will export this project as artifact so that it can be used in other projects. This artifact will be pushed to GitHub. Here is the pom.xml of the project:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.anupam</groupId>
    <artifactId>test-repo</artifactId>
    <version>1.0.0</version>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    <distributionManagement>
        <repository>
            <id>internal</id>
            <url>file://${project.build.directory}/mvn-repo</url>
        </repository>
    </distributionManagement>
</project>

The most important part of the pom.xml is:

<distributionManagement>
    <repository>
        <id>internal</id>
        <url>file://${project.build.directory}/mvn-repo</url>
    </repository>
</distributionManagement>

The URL can be anything valid. Now execute the following command:

 mvn deploy 

It will generate the artifact as shown in the below diagram:

Image title


Pushing the Artifact to GitHub

Let's create an empty GitHub repository. Let's suppose its URL is https://github.com/anupamgogoi0907/artifacts.git.

Now clone this repository to your system:

>test-repo git clone https://github.com/anupamgogoi0907/artifacts.git

Copy the artifact generated under the mvn-repo folder (in the previous step), and then push it to the repository.

It should look something like this in your GitHub account:

Image title

At this stage, we have pushed our artifact to our GitHub repository. Now let's try to make use of it.

Using the GitHub Artifact

Now let us create a new Maven project and use the artifact we pushed to GitHub in the previous step.

Add the following repository declaration in the pom.xml.

<repositories>
    <repository>
        <id>mvn-repo</id>
        <url>https://rawgit.com/anupamgogoi0907/artifacts/master</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

And that's it. Execute the  mvn compile command and the artifact will be downloaded from the repository.

Conclusion

In this article, I have shown how easy it is to use the GitHub as your repository manager. Remember, this is just an exercise to show how it can be done, and isn't the professional way to host a repository.

Repository (version control) GitHub Apache Maven

Opinions expressed by DZone contributors are their own.

Related

  • Automate Web Portal Deployment in Minutes Using GitHub Actions
  • How GitHub Codespaces Helps in Reducing Development Setup Time
  • A Comprehensive Guide to GitHub
  • Deploy MuleSoft App to CloudHub2 Using GitHub Actions CI/CD Pipeline

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook