Maven Warehouse - Introduction to Private Service

Keywords: nexus Maven xml Oracle

What is private service?

Private servers, or private servers, are an internal Maven repository through which a company's internal Maven project needs to download dependent packages and plug-ins. Nexus is a common private Maven server, which is usually used internally.

Common Functions and Introduction

Designate your Maven project to private service address
Download project index of central repository from private service
Download project index of central repository from private service
Upload third party project jar to private service for other projects

After installation of Nexus, the default port is 8081, access http://192.168.x.x:8081/nexus/index.html Open the page. The default password is admin/admin123.

Below is a screenshot of the logged-in:

Repositories in the left menu are more commonly used.

The general types of warehouses used are hosted and proxy.
Hosted represents the host repository and is used to publish components that are not allowed by third parties, such as oracle drivers, commercial software jar packages, and company-developed jar packages.

Proxy represents the agent of remote warehouses, the most typical of which are Maven's official central warehouse, JBoss warehouse and so on. If the user computer local warehouse of Maven project is built without dependency packages, it will go to Proxy proxy site (i.e. Nexus private service) to download, then if the proxy site does not have this dependency package, it will go to remote central warehouse to download dependencies. The agent site (private service) is downloaded successfully and then downloaded to the user's local warehouse.

In fact, Maven's default warehouse is usually enough for most projects. Configure new warehouses in special cases, such as adding JBoss warehouses (configure the specified url).

As follows, the relationship diagrams of user computers, private services and remote central warehouses are described.

Types of warehouses

hosted type warehouse, internal project release warehouse
release Warehouse of release Module in releases Internal Module
Snpshots publishes the repository of internal SNAPSHOT modules
3rd party third-party dependent warehouse, this data is usually downloaded by internal staff after publishing
proxy type warehouse, looking for data warehouse from remote central warehouse
group warehouse, a warehouse set up for the convenience of our developers

Maven Project Index

Download the Maven Project Index, which is designed to enable users to find dependent functions at private service sites.

Save the background and run a task. Click on the Scheduled Tasks option in the menu bar (and then in the left menu Administration group) to see that there is a task in RUNNING. When the download is complete, the Maven index can be used, and the relevant information can be found by entering the items to be searched in the search bar. For example, spring-core, the following figure is a demonstration (you can retrieve its relevant information, including how to configure dependency information):

Configuration and Use of Private Servers

To use this private service warehouse, we first configure the designated warehouse of relevant private service information in the project pom. The following fragments need to be configurated in the pom.xml of the maven project.

    <repositories>  
        <repository>  
            <id>nexus</id>  
            <name>nexus</name>
            <url>http://192.168.x.x:8081/nexus/content/groups/public/</url>  
            <releases>  
                <enabled>true</enabled>  
            </releases>  
            <snapshots>  
                <enabled>true</enabled>  
            </snapshots>  
        </repository>  
    </repositories> 

The following section sets up the plug-in repository:

    <pluginRepositories>  
        <pluginRepository>  
            <id>nexus</id>  
            <name>nexus</name>  
            <url>http://192.168.x.x:8081/nexus/content/groups/public/</url>  
            <releases>  
                <enabled>true</enabled>  
            </releases>  
            <snapshots>  
                <enabled>true</enabled>  
            </snapshots>  
        </pluginRepository>  
    </pluginRepositories> 

After this configuration is completed, the project will download the components in private clothes.

Because we configure this configuration in the pom.xml of a specific project, it will only work for one project. If we want to enable this private service configuration for all Maven projects on our computers, we need to configure the private service information into maven's global configuration file settings.xml, which is located in apache-maven/conf/settings.xml.

Modify the profiles in settings.xml to read:

  <profiles>
    <profile>
       <id>nexus-central</id>
       <repositories>
        <repository>
          <id>nexus-central</id>
          <name>nexus-central</name>
          <url>http://192.168.1.117:8081/nexus/content/groups/public/</url>
          <layout>default</layout>
          <snapshotPolicy>always</snapshotPolicy>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
     </profile>
  </profiles>

And activate the profile

  <activeProfiles>  
    <activeProfile>nexus-central</activeProfile>     
  </activeProfiles>  

After that, all local Maven projects will download components in this private app (which is more convenient).

Project release to private service

Add the following configuration to the pom.xml of the maven project:

    <distributionManagement>
        <repository>
            <id>nexus-releases</id>
            <name>Nexus Release Repository</name>
            <url>http://192.168.x.x:8081/nexus/content/repositories/releases/</url>
        </repository>
        <snapshotRepository>
            <id>nexus-snapshots</id>
            <name>Nexus Snapshot Repository</name>
            <url>http://192.168.x.x:8081/nexus/content/repositories/snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

This configuration is not enough. Publishing a project to a private service is bound to fail, because we have not configure permissions. There should be 401 error codes for publishing a project without configuring permissions. Therefore, we need to configure the private service permission account information in maven's settings.xml, as follows:

    <!-- servers The attributes of the node are used when publishing to the warehouse -->
    <servers>
        <server>
            <!-- this ID Need and project pom.xml in distributionManagement Lower ID Agreement -->
            <id>nexus-releases</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
        <server>
            <!-- this ID Need and project pom.xml in distributionManagement Lower ID Agreement -->
            <id>nexus-snapshots</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
    </servers>

Note that the id in Repository must be the same as the id in server, remember!! Otherwise, there will be permission problems.

Then run the command to publish
mvn clean deploy

After the console prompt has been successfully released, go into the warehouse on the private service and see if there is a project just released.

Host Repository - 3rd party

If we download Oracle's driver jar package and want to use it for other project groups, we need to upload the jar package. Select the host library 3rd party, and then select Artifact Upload to upload to the host space.

Upload and view the results in Browse Index.

Posted by ducey on Sat, 20 Apr 2019 09:12:33 -0700