24-Nexus3.X configuration

Introduction to Maven
Apache Maven is an innovative software project management and synthesis tool.
Maven provides a new concept for managing project builds based on Project Object Model (POM) files, which can manage project builds, reports and files from a central piece of information.
The most powerful feature of Maven is the ability to automatically download project dependencies.
Maven provides a complete lifecycle framework for developers to build. The development team can automatically complete the basic tool construction of the project, Maven uses a standard directory structure and default build life cycle.
In the case of multiple development team environments, Maven can be set up to complete the configuration work in a very short time by standard. Since most projects are simple to setup and reusable, Maven makes the developer's job easier while creating reports, checking, building and testing automation setups.

The main goal of Maven is to provide developers:
1) The project is a comprehensive model that is reusable, easy to maintain, and easier to understand.
2) Plugins or interactive tools, this declarative pattern.

Private server introduction
Private server refers to a private server, which is a special remote warehouse set up on a local area network. The purpose is to act as a proxy for remote warehouses and deploy third-party builds. With the private server, when Maven needs to download the component, it directly requests the private server, and if it exists on the private server, it will be downloaded to the local warehouse; otherwise, the private server will request an external remote warehouse, download the component to the private server, and then provide it to the local warehouse for download.





Nexus Introduction
Nexus is a powerful Maven repository manager that greatly simplifies the maintenance of local internal repositories and access to external repositories.
If a public Maven repository server is used, the required artifacts (Artifacts) can be downloaded from the Maven central repository, but this is usually not a good practice.
The normal practice is to set up a Maven repository server locally, that is, using the Nexus private server, you can fully control the access and deployment of each Artifact in the repository you maintain in only one place.
Nexus maintains local warehouses while acting as remote warehouses to reduce the load of central warehouses and save extra network bandwidth and time. Nexus private server can meet such needs.
Nexus is an "out of the box" system that does not require a database, it uses the file system plus Lucene to organize data.
Nexus uses ExtJS to develop the interface, uses Restlet to provide complete REST APIs, and integrates with Eclipse through m2eclipse.
Nexus supports WebDAV and LDAP secure authentication.
Nexus also provides a powerful warehouse management function, component search function, it is based on REST, friendly UI is an extjs REST client, it takes up less memory, based on a simple file system instead of a database.

Why build a Nexus private server?
If there is no Nexus private server, all the components we need need to be downloaded to the local through maven's central warehouse and third-party Maven warehouse, and everyone in a team repeatedly downloads components from the maven warehouse, which undoubtedly increases the load of the warehouse And waste the bandwidth of the external network. If the network speed is slow, it will also affect the progress of the project. In many cases, the development of the project is carried out on the intranet, what should I do if I cannot connect to the maven warehouse? How can the developed public components be used by other projects? At this time, we have to build our own maven private server for our team, which not only saves network bandwidth but also speeds up the process of project construction. Of course, the prerequisite is that your private server has all the components required for the project.

In a word, the benefits of building a nexus private server locally are:
1) Accelerate the build;
2) Save bandwidth;
3) Save the bandwidth of the central maven warehouse;
4) Stability (to cope with the problem of the central server);
5) Control and auditing;
6) Ability to deploy third-party components;
7) Ability to create local internal repositories;
8) Ability to create public repositories
These advantages make Nexus increasingly the most popular Maven repository manager.

1. Download the tar package on the official website
2. Unzip
3. Enter the bin directory
4. Execute ./nexus run
5. Visit http://Deploy nexus address: 8081




The above page appears, indicating that the nexus configuration is successful!
Click "Log in" in the upper right corner,
enter the default user name (admin) and default password (admin123) to log


in. You can view the nexus system information in "Management".




The concept of Nexus warehouse classification:
1) Maven can download components directly from the host warehouse, You can also download components from the proxy warehouse, and the proxy warehouse indirectly downloads and caches components from the remote warehouse
2) For convenience, Maven can download components from the warehouse group, and the warehouse group has no time content (represented by a dotted line in the figure below, it is It will turn to the included host repository or proxy repository to get the actual component content).





Nexus's web interface function introduction

1. Browse Server Content



1.1 Search
This is similar to the search function on the Maven repository, which is to find out which packages are available from the private server.
Note:
1) Fuzzy search is supported at the Search level, as shown in the figure:



1.2 Browse



1) Assets
This is to see all resources, including Jar, and some description information of Jar.
2) Components
can only see Jar packages here.

2. Server Adminstration And configuration

The premise of seeing this option is to log in. As the login method has been introduced above, click the login button of "Sign In" in the upper right corner and enter admin/admin123. After the login is successful, you can see this Function, as shown in the figure:



2.1 The place where Blob Stores
files are stored, if a directory is created, it corresponds to a directory in the file system, as shown in the figure:



2.2 Repositories



1) Proxy central Maven warehouse Proxy
Here is the meaning of proxy, proxy central Maven Warehouse, when the PC accesses the central library, it is first downloaded to the Nexus warehouse through the Proxy, and then downloaded from the Nexus warehouse to the local PC.
This kind of advantage only needs one of them to come down from the central repository. In the future, everyone will go from the Nexus private server. The private server is generally deployed on the intranet, which greatly saves bandwidth.
Specific steps to create a Proxy
1--Click the "Create Repositories" button




2--Select the type to be created



3--Fill in the details
Name: is to name the proxy
Remote Storage: The address of the proxy, Maven's address is: https: https: //repo1.maven.org/maven2/
Blob Store: Select the storage path of the agent download package



2) Hosted
Hosted means the host machine, which is how to put the third-party Jar on the private server.
There are three ways of hosting, Releases, SNAPSHOT, Mixed
Releases: Generally, it is the released Jar package
Snapshot: Unreleased version
Mixed:
The creation of mixed Hosted is the same as that of Proxy, and the specific steps are basically the same as above. As follows:









Notes:
Allow Redeploy: Allow redeployment
Disable Redeploy: Disable redeployment
Read-Only: Read-only




3. Repository Group (Repository Group)
usually contains multiple proxy warehouses and host warehouses, as long as the warehouse group is introduced into the project Packages that can be downloaded to the proxy warehouse and host warehouse, such as:

maven-public
nuget-group

4. Log and data analysis




========================== =====Introduction =======================================
1. Proxy warehouse (Proxy Repository)
As the name implies, it is a proxy for third-party repositories, such as:
   maven-central
   nuget.org-proxy

Version Policy:
   Release: Official version
   Snapshot: Snapshot version
   Mixed: Mixed mode

Layout Policy:
   Strict: Strict
   Permissive: Loose

2. The Hosted Repository

stores locally uploaded components and resources, such as:
  maven-releases
  maven-snapshots
  nuget-hosted

Deployment Policy:
  Allow Redeploy : Allow redeployment
  Disable Redeploy: Disable redeployment
  Read-Only: Read-only

3. Repository Group (Repository Group)
usually contains multiple agent warehouses and host warehouses, as long as the warehouse group is introduced in the project, it can be downloaded to the agent warehouse and host Packages in the warehouse, such as:

maven-public
nuget-group

integration with Maven
1. Servers configuration authentication information
Add Nexus authentication information in Maven settings.xml:

<server>
  <id>nexus-releases</id>
  <username>admin</username>
  <password>admin123</password>
</server>

<server>
  <id>nexus-snapshots</id>
  <username>admin</username>
  <password>admin123</password>
</server>

 


   nexus-releases: 用于发布Release版本
   nexus-snapshots: 用于发布Snapshot版本

Release版本与Snapshot版本的区分:
  Release: 4.3.0
  Snapshot: 4.3.0-SNAPSHOT
  在项目POM.xml中设置的版本号添加SNAPSHOT标识的都会发布为SNAPSHOT版本,没有SNAPSHOT标识的都会发布为Release版本。
  SNAPSHOT版本会自动加一个时间作为标识,如:4.3.0-SNAPSHOT发布后为变成4.3.0-SNAPSHOT-20160712.114532-1.jar

2. 配置自动化部署构件
在POM.xml中添加以下代码:

<distributionManagement>  
  <repository>  
    <id>nexus-releases</id>  
    <name>Nexus Release Repository</name>  
    <url>http://127.0.0.1:8081/repository/maven-releases/</url>  
  </repository>  
  <snapshotRepository>  
    <id>nexus-snapshots</id>  
    <name>Nexus Snapshot Repository</name>  
    <url>http://127.0.0.1:8081/repository/maven-snapshots/</url>  
  </snapshotRepository>  
</distributionManagement> 

 
注意事项:
ID名称必须要与settings.xml中Servers配置的ID名称保持一致。
项目版本号中有SNAPSHOT标识的,会发布到Nexus Snapshots Repository, 否则发布到Nexus Release Repository,并根据ID去匹配授权账号。

3. 部署到Nexus仓库
mvn deploy

4. 上传第三方JAR包
Nexus 3.0不支持页面上传,可使用maven命令:
# 如第三方JAR包:aliyun-sdk-oss-2.2.3.jar

mvn deploy:deploy-file 
  -DgroupId=com.aliyun.oss 
  -DartifactId=aliyun-sdk-oss 
  -Dversion=2.2.3 
  -Dpackaging=jar 
  -Dfile=D:\aliyun-sdk-oss-2.2.3.jar 
  -Durl=http://127.0.0.1:8081/repository/maven-3rd/ 
  -DrepositoryId=nexus-releases

 
注意事项:
1.建议在上传第三方JAR包时,创建单独的第三方JAR包管理仓库,便于管理有维护。(maven-3rd)
2.-DrepositoryId=nexus-releases 对应的是settings.xml中Servers配置的ID名称。(授权)

5. 使用代理中央仓库

<repositories>
    <repository>
        <id>nexus</id>
        <name>Nexus Repository</name>
        <url>http://127.0.0.1:8081/repository/maven-public/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>nexus</id>
        <name>Nexus Plugin Repository</name>
        <url>http://127.0.0.1:8081/repository/maven-public/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
    </pluginRepository>
</pluginRepositories>

 

注意事项:
在开发中如果有严格的管理要求,可将SNAPSHOT和RELEASE单独配置。
有插件依赖时配置插件仓库,默认会使用Maven中央仓库。

 

参考 

https://segmentfault.com/a/1190000005966312#articleHeader12

http://www.cnblogs.com/kevingrace/p/6201984.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326299714&siteId=291194637