Use site-maven-plugin to build a public warehouse on github

Posted May 27, 20205 min read

\ [toc ]

Use site-maven-plugin to build a public warehouse on github


Maven is a build tool that we often use in the development of java programs. During the team development process, if we want to share the jar package we have written to others, we usually need to build the maven warehouse ourselves and then write the jar The package is uploaded to the maven repository for other users to use.

Building a maven warehouse requires a server and a domain name. For a company, there are many domain names and servers. However, if we or a small team want to share some very useful jar packages for others to use, it is too much trouble.

Good news from Github has frequently appeared recently. First, the number of repositories and collaboration users has been removed from individual users. Later, corporate users have also been upgraded and reduced prices. If the warehouse is not large, you can move the warehouse to github.

More exciting content and see:

For more information, please visit


To build a maven repository on github, we need to use the maven plugin:site-maven-plugin. Because you want to connect to github, you need to set github's oauth permissions. It is possible to use the username and password directly, but it is not safe to do so, we do not recommend it.

As shown in the above figure, create an access token in Settings-> Developer settings-> Personal access tokens, the required permissions are as follows:

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

With permissions, next we create a github-maven-repository to store data as an mvn repository.

If the generated address is:

Configure GitHub permissions in maven

In this step, we need to edit the setting.xml file. Generally speaking, this file is in ~/.m2/settings.xml.

We need to add a Server, if you directly use the github username and password, it will look like this:

   <id> github </id>
    <username> YOUR_USERNAME </username>
    <password> YOUR_PASSWORD </password>

Earlier we said that it is not safe to directly use the user name, we can use the oauth key created above:

    <id> github </id>
    <password> OAUTH2TOKEN </password>

This id will be used later in the pom.xml file configuration, here we first write down.

Configure deploy-plugin

Our goal is to generate maven dependencies containing jar packages. Before uploading the jar package to the remote warehouse, we need to generate it locally.

First configure a local repository:

            <id> maven.repo </id>
            <name> Local Staging Repository </name>
            <url> file://${}/mvn-repo </url>

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

Next, we need to use maven-deploy-plugin to specify the deployment of the package to the local repository we just specified.

            <artifactId> maven-deploy-plugin </artifactId>
            <version> 2.8.2 </version>
                <altDeploymentRepository> maven.repo ::default ::file://${}/mvn-repo </altDeploymentRepository>

Configure site-maven-plugin

Now we can use site-maven-plugin:

            <!-Deploy the web site->
            <groupId> com.github.github </groupId>
            <artifactId> site-maven-plugin </artifactId>
            <version> 0.12 </version>
                        <goal> site </goal>
                    <!-select the Maven phase in which the plugin will be executed->
                    <phase> deploy </phase>
                        <!-Plugin configuration goes here->
                        <server> github </server>
                        <!-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->
                        <merge> true </merge>
                        <outputDirectory> ${}/mvn-repo </outputDirectory>
                        <branch> refs/heads/mvn-repo </branch>
<!-<include> **/* </include>->

Pay attention to the following points during use:

  1. The goals of site-maven-plugin are sites, which need to be associated with the deployment phase of maven, so that when we execute mvn deploy, site-maven-plugin is automatically run.

  2. GitHub permission configuration, we can set server = github in the configuration, and can also configure the following global variables:

         <> github </>
  3. You need to specify repositoryName and repositoryOwner, otherwise an error will be reported.

  4. message indicates the message submitted to github.

  5. The branch submitted to github by default is refs/heads/gh-pages, here we have customized one.

Ok, everything is configured, we can run mvn deploy:

As you can see from the picture above, there is already a sharable project on github.

How to use this shared project

It is very simple to use, just add the corresponding dependency and repository in the pom.xml file:

    <groupId> YOUR.PROJECT.GROUPID </groupId>
    <artifactId> ARTIFACT-ID </artifactId>
    <version> VERSION </version>

    <id> ARTIFACT-ID </id>

to sum up

Use the benefits that Github brings us.

Example of this article \ [
learn-java-base-9-to-20 ]([] ( 20))

Author:flydean program those things

Link to this article:

Source of this article:flydean's blog

Welcome to pay attention to my public number:those things of the program, more exciting waiting for you!