Using site Maven plugin to build public warehouse on GitHub



Using site Maven plugin to build public warehouse on GitHub

brief introduction

Maven is a build tool that we often use in developing Java programs. In the process of team development, if we want to share our jar package to others, we usually need to build our own Maven repository, and then upload the jar package to Maven warehouse for other users to use.

Building Maven repository requires servers and domain names. For companies, there are many domain names and servers. However, it would be too troublesome for us or small teams to share some very useful jar packages for others to use.

Recently, GitHub has seen a lot of good news. First, the number of repositories and collaborative users for individual users has been removed, and then enterprise users have been upgraded and reduced prices. If the warehouse is small, you can move the warehouse to GitHub.

See more:

  • A series of tutorials from introduction to abandonment of blockchain – covering cryptography, super ledger, Ethereum, Libra, bitcoin, etc
  • Spring boot 2. X Series tutorials: seven days to master spring boot – continuous update
  • Spring 5. X series of tutorials: meet your imagination of spring 5 – constantly updated
  • Java programmer’s road to becoming an expert (2020 Edition) – continuous update, with detailed articles and tutorials

For more information, please visit

preparation in advance

To build Maven repository on GitHub, we need to use the Maven plug-in: site Maven plugin. Because you want to connect to GitHub, you need to set the OAuth permission of GitHub. It’s OK to use user name and password directly, but it’s not safe. We don’t recommend it.

Using site Maven plugin to build public warehouse on GitHub

As shown in the above figure, create an access token in Settings > developer Settings > personal access tokens. The required permissions are as follows:

Using site Maven plugin to build public warehouse on GitHub

Using site Maven plugin to build public warehouse on GitHub

Note that the user’s permission must be selected, otherwise an exception will be reported later.

With permissions, we will create a GitHub Maven repository to store data as an MVN repository.

If the generated address is:…

Configuring GitHub permissions in maven

We need to edit this step setting.xml File. Generally speaking, this file is in ~ /. M2/ settings.xml 。

We need to add a server. If the user name and password of GitHub are used directly, it will be as follows:


As we mentioned earlier, it is not safe to use the user name directly. We can use the OAuth key created above:


This ID will be in the back pom.xml It is used in file configuration. Here we will write it down first.

Configure deploy plugin

Our goal is to generate Maven dependencies that contain jar packages. Before uploading the jar package to the remote repository, we need to do it locally.

First configure a local repository:

            <name>Local Staging Repository</name>

Above, we have specified to create MVN repo under the build directory of the project to store the locally typed package.

Next, we need to use Maven deploy plugin to deploy the package to the local repository we just specified.


Configure site Maven plugin

Now we can use the site Maven plugin

            <!-- Deploy the web site -->
                    <!-- select the Maven phase in which the plugin will be executed -->
                        <!-- Plugin configuration goes here -->
                        <!-- The commit message -->
                        <message>init git maven repository</message>
                        <!-- The location where the site is uploaded -->
                        <repositoryName>github-maven-repository</repositoryName> <!-- github repo name -->
                        <repositoryOwner>flydean</repositoryOwner> <!-- organization or user name  -->
                        <!-- Use merge or override the content -->
<!--                        <includes>-->
<!--                            <include>**/*</include>-->
<!--                        </includes>-->

Pay attention to the following points in use:

  1. The goals of site Maven plugin are sites, which need to be associated with Maven’s deploy phase to automatically run site Maven plugin when we execute MVN deploy.
  2. For permission configuration of GitHub, we can set server = GitHub in configuration, or configure the following global variables:
  1. You need to specify the repository name and repository owner, otherwise an error will be reported.
  2. Message represents the message submitted to GitHub.
  3. By default, the branch submitted to GitHub is refs / heads / GH pages. Here we have customized one.

Now that everything is configured, we can run MVN deploy:

Using site Maven plugin to build public warehouse on GitHub

As you can see from the above figure, there is already a shareable project on GitHub.

How to use this shared project

It’s very easy to use, just use the pom.xml Add the corresponding dependency and repository to the file




Let’s use the benefits GitHub brings us.

Examples of this article[

The author of this article: what about the flybean program

Link to this article:

Source: flyden’s blog

Welcome to my official account: the procedures, the more wonderful things waiting for you!