The Maven server

Maven is the repository I use most in development, and I can’t remember how many battles I’ve had with POM files

There are many excellent projects in the open warehouse, but it is inevitable that there are special requirements. Besides excessive requirements, there are many modules, and even colleagues’ projects are referenced

The traditional JAR package approach is backward and inelegant

The nexus3’s minimum 2gb memory startup limit killed my Tencent cloud small server

Using Github Repository as a Maven Repository tutorial is pretty much the same on the Web, but the practice is complicated, and there were problems when I did the version update

Only Github Packages came to my rescue

Set up

Github Packages

Before using Github Packages, we need to do the following three steps:

  1. Have a Github account
  2. Generate a token for access
  3. Create a repository for saving, which I like to call maven-repo

The above steps can be carried out in the browser, and there are many online tutorials, not to repeat

Modifying Maven Configuration

The configuration file is ${MavenHome}/conf/settings.xml

We need to change the sum inside

<servers>
    <server>
        <id>Service ID. I used github</id>
        <username>Your Github account name</username>
        <password>Your Github access token</password>
    </server>
</servers>
<profiles>
    <profile>
        <id>github</id>
        <repositories>
            <repository>
                <id>central</id>
                <url>https://repo1.maven.org/maven2</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
			</repository>
			<repository>
                <id>The service ID must be the same as that in the server label</id>
                <name>GitHub account name Apache Maven Packages</name>
                <url>https://maven.pkg.github.com/Github account name/used to save the names of the warehouse</url>
            </repository>
        </repositories>
    </profile>
</profiles>
Copy the code

If you’re using Maven with IDEA, you can just write settings. XML and override it in the configuration

Example Modify poM files

Now that the Maven repository is ready, just follow the normal process and set up the package to publish:

<distributionManagement>  
    <repository>    
        <id>The service id</id>    
        <name>GitHub account name Apache Maven Packages</name>
        <url>https://maven.pkg.github.com/Github account name/used to save the names of the warehouse</url>  
    </repository>
</distributionManagement>
Copy the code

The contents of the tag are exactly the same as the configuration in maven in our previous step

All we need to do is run the package command and our private dependencies are published

Pay attention to a pit

Maven provides Github Packages for private servers, which require Github token authentication to be configured in Maven. This can be very difficult for non-Github teams to work with.