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

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Enterprise AI Trend Report: Gain insights on ethical AI, MLOps, generative AI, large language models, and much more.

2024 Cloud survey: Share your insights on microservices, containers, K8s, CI/CD, and DevOps (+ enter a $750 raffle!) for our Trend Reports.

PostgreSQL: Learn about the open-source RDBMS' advanced capabilities, core components, common commands and functions, and general DBA tasks.

AI Automation Essentials. Check out the latest Refcard on all things AI automation, including model training, data security, and more.

Related

  • A Comprehensive Guide to GitHub
  • Deploy MuleSoft App to CloudHub2 Using GitHub Actions CI/CD Pipeline
  • Unlock the Power of Software Heritage Archive
  • GitOps: Flux vs Argo CD

Trending

  • Scaling Java Microservices to Extreme Performance Using NCache
  • Long Tests: Saving All App’s Debug Logs and Writing Your Own Logs
  • AI and Rules for Agile Microservices in Minutes
  • Deploying to Heroku With GitLab CI/CD
  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
Like (35)
Save
Tweet
Share
65.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

  • A Comprehensive Guide to GitHub
  • Deploy MuleSoft App to CloudHub2 Using GitHub Actions CI/CD Pipeline
  • Unlock the Power of Software Heritage Archive
  • GitOps: Flux vs Argo CD

Partner Resources


Comments

ABOUT US

  • About DZone
  • Send feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: