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
Please enter at least three characters to search
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

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

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

  • Create Your Own AI-Powered Virtual Tutor: An Easy Tutorial
  • How the Go Runtime Preempts Goroutines for Efficient Concurrency
  • Mastering Fluent Bit: Installing and Configuring Fluent Bit on Kubernetes (Part 3)
  • While Performing Dependency Selection, I Avoid the Loss Of Sleep From Node.js Libraries' Dangers
  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
66.4K 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
Oops! Something Went Wrong

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

ABOUT US

  • About DZone
  • Support and 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:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!