Use site-maven-plugin to build public warehouses on github

brief introduction

Maven is a building tool that we often use in developing java programs. During team development, if we want to share our own written jar packages with others, we usually need to build our own Maven repository and upload the written jar packages to the Maven repository for other users to use.

Building a maven repository requires a server and domain name. There are a lot of domains and servers for companies, but it would be too cumbersome for us or small teams to share some very useful jar packages for others to use.

Recently, the good news for Github has been that the number of repositories and collaborators has been removed for individual users, followed by upgrades and price reductions for enterprise users.If the warehouse is small, you can move it to github.

More interesting and see:

More please visit

preparation in advance

To build a maven repository on github, we need to use maven's plug-in: site-maven-plugin.Because you want to connect to github, you need to set the oauth permission for github.It's okay to use a username password directly, but it's not safe and we don't recommend it.

As shown in the figure above, create an access tokens in Settings->Developer settings->Personal access tokens with the following permissions:

Note that the user must choose permissions here, otherwise an exception will be reported later.

With privileges, let's create a github-maven-repository to store data as an mvn repository.

If the generated address is:

Configure GitHub permissions in maven

This step we need to editSetting.xmlFile, normally this file is ~/.m2/settings.xml.

We need to add a Server that uses github's username password directly, like the following:


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


This id will followPom.xmlThis is used in the file configuration, so let's write it down here first.

Configure deploy-plugin

Our goal is to generate maven dependencies that contain jar packages.Before uploading jar packages to a remote warehouse, we need to build them locally.

Configure a local repository first:

            <name>Local Staging Repository</name>

Above we specified that mvn-repo was created under the project's build directory to store locally typed package s.

Next, we need to use maven-deploy-plugin to specify that the packages will be deployed to the local repository we just specified.


Configure site-maven-plugin

Now we can use 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>-->

The following points should be noted during 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 deployment.

  2. Github's permission configuration, we can set server=github in the configuration, or we can configure the following global variables:

  1. repositoryName and repositoryOwner need to be specified, otherwise errors will be reported.

  2. Message represents a message submitted to github.

  3. By default, the branch submitted to github is refs/heads/gh-pages, which we customize here.

Okay, everything is configured and we can run mvn deploy:

As you can see from the above image, there is already a project on github that can be shared.

How to use this shared project

It's easy to use, just need toPom.xmlAdd the appropriate dependencies and repositories to the file:




Github's benefits for us. Get them started.

Examples of this article learn-java-base-9-to-20

Author: Fldean Programs

Links to this article:

Source: Fldean's blog

Welcome to my Public Number: program stuff, more exciting waiting for you!

Tags: Programming github Maven Spring Java

Posted on Tue, 26 May 2020 15:55:01 -0700 by eddiegster