Maven Project Construction

Maven Repository Mirror

Maven Repository

There are two main types of Maven repositories:

  • Remote repository: equivalent to a public repository, most of which can be accessed in the form of URL
  • Local repository: a folder stored on the local disk (the path is similar to .m2/repository)

Among them, there are three main types of remote repositories:

  • Central repository: http://repo1.maven.org/maven2/
  • Private server: Self-built Maven repository
  • Other public repositories: Maven repositories accessible from other public networks

Repositories mainly store various components (jar packages or Maven plug-ins) needed for Maven construction. When requesting components from the repository, it will first check whether the local repository already exists. If it does not exist, it will request from the remote repository and cache it locally.

Maven Mirror Repository

Mirror is equivalent to an interceptor. It will intercept Maven’s related requests to the remote repository and redirect the remote repository address in the request to the address configured in the mirror.

Example 1: The value of mirrorOf is central, which means that the configuration is a mirror of the central repository. Any request for the central repository will be forwarded to the mirror repository http://192.168.1.200:8081

    <mirror>
      <id>maven.gridworkz</id>
      <name>gridworkz maven</name>
      <url>http://192.168.1.200:8081/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>

Example 2: The value of mirrorOf is *, it means that the configuration is a mirror of all repositories, and any request for remote repositories will be forwarded to this mirror

<mirror>
      <id>maven.all.gridworkz</id>
      <name>gridworkz all maven</name>
      <url>http://192.168.1.200:8081</url>
      <mirrorOf>*</mirrorOf>
    </mirror>
Other Advanced Operations
<mirrorOf>*</mirrorOf> # means all remote repositories
<mirrorOf>external:*</mirrorOf> # In addition to the local repository to the remote repository
<mirrorOf>repo1,repo2</mirrorOf> # match repo1 and repo2
<mirrorOf>*,!repo1</miiroOf> # matches all remote repositories except repo1

Build a Maven project through Kato. If the Mirror function is not disabled, by default, the mirror will be defined by adding a global Maven configuration file when building the source code, that is, any request to a remote repository will be redirected to maven.gridworkz, If you do not connect your private server to rbd-repo, it may cause the components in the private server to fail to download normally and cause the source code build to fail. The default configuration is as follows

  <mirror>
    <id>gridworkz-repo</id>
    <name>gridworkz repo</name>
    <url>http://maven.gridworkz</url>
    <mirrorOf>*</mirrorOf>
  </mirror>

Since the mirror repository completely shields the mirrored repository, when the mirrored repository is unstable or the service is stopped, Maven will still not be able to access the mirrored repository and therefore cannot download components.

Kato build source Maven mirror repository parameter description

1. Disable Maven Mirror: The mirroring function is not disabled by default, that is, the Maven global configuration file will be added when the source code is built, and the repository request will be redirected to the mirror repository
2. MAVEN MIRROROF configuration: only the central (central repository) is mirrored by default, if it is empty, all repositories will be mirrored by default
3. MAVEN MIRROR_URL: The default mirror repository address is maven.gridworkz

Among them, MAVEN MIRROROF and MIRROR_URL only take effect when Maven Mirror is not disabled

More Build source parameters description reference

maven.gridworkz is served by the built-in rbd-repo of Kato by default.

Kato component rbd-repo brief introduction

Kato implements the Maven repository management function through the rbd-repo component, which is based on the Artifactory open source version, and its source code is hosted in [gridworkz/rbd-repo] (https://github.com/gridworkz/rbd-repo.git), if you need to customize your own rbd-repo, you can refer to [rbd-repo guide](/docs/user-operations/op-guide/op-repo /)

By default, rbd-repo mirrors the following remote repositories:

  • aliyun-central
  • central
  • jcenter
  • spring
  • spring-plugin

If you need to mirror the above repository, you can configure the MirrorOF value to central,jcenter through Build Source

The default rbd-repo access address is: http://management node IP:8081, administrator username and password: admin/password

If there are multiple management nodes, all management nodes need to be configured at the same time when connecting to a private repository

In addition, there are mainly three types of repositories in rbd-repo. The use of Local repositories and Remote repositories will be described in detail later:

  • Local: Local private repository for internal use, the uploaded components will not be synchronized with the outside (used as a company’s internal private server);
  • Remote: Remote repository, used to proxy and cache public repositories. It is not possible to upload private components to this type of repository (the docking company already uses private servers);
  • Virtual: Virtual repository, not a real repository on storage, it is used to organize local repositories and remote repositories (maven.gridworkz).

Kato docks with a private Maven repository

The company has its own Maven private server repository, which can be connected with Kato through the rbd-repo component.

Note: If your private server is Nexus3 or Alibaba Cloud Maven repository, you cannot use rbd-repo for mirror proxy caching.

Solution: Method 1. Disable Kato’s Mirror configuration, set it in the project build source and enable the clear build cache configuration item at the same time, and define the relevant in pom.xml Warehouse information
Method 2. Use Nexus2 or use the built-in rbd-repo service of Kato

Example docking with internal private Maven repository

Here is an example to illustrate the docking method:

1. Create a remote type repository

Visit http://management node IP:8081 and log in with the administrator account (admin/password).

Admin Repositories choose to add Remote repository

Choose to create a new Remote (remote) repository

Remote (remote) repository type select Maven

Configure the Remote (remote) repository, in which you need to pay attention to the Maven URL can be accessed through the browser to list related components normally

_Repository Key: _ The name of the repository, which cannot be the same as other repositories. The example repository name is: demo-repo

_URL: _ The address of the remote repository If your external Maven repository is built by Artifactory, the address is similar to http://<maven domain name>/artifactory/list/<repository name>/, if your external repository It is built by Nexus and the address is similar to http://maven domain name/nexus/content/repositories/<repository name>/

After filling in the URL address, you can click the Test button to test the validity of the connection. If the connection is valid, click the “Save & Finish” button to complete the creation.

2. Add the new repository to the libs-release virtual repository (important)

The internal repository creates a virtual repository named libs-release by default. The virtual repository (virtual) is not a real repository. It is a logical unit used to organize local repositories and remote repositories. Since the cloud help mirrors all repository addresses, the remote repository needs to be added to the virtual repository.

Admin ——> Repositories ——> Virtual select libs-release

3. Verify that the addition is successful

Visit http://<management node>:8081/artifactory/list/libs-release/ or visit maven.gridworkz for the management node to see if you can list your newly added private server components.

Use Kato’s built-in Maven repository

If you don’t have a Maven repository management system, you can directly use Kato’s built-in Maven repository management system. Here are the steps:

  1. Create a Maven repository of type Local. Example Create a Maven repository of type Local with the name repo-local
  2. Upload your own jar package to the local repository repo-local
  3. View dependency declaration information
  4. Add repo-local to the libs-release virtual repository

Visit http://<management node>:8081/artifactory/list/libs-release/ or visit maven.gridworkz for management node to see if you can list your newly added components.