Configure Nexus Warehouses, deploy artifacts to nexus warehouses

Source: Internet
Author: User
Tags maven central sonatype

In the previous section, we described how to configure the Nexus system to be installed, and this section describes the use of the Nexus
1. Login

In the Red section click Login, enter the user name and password admin/admin123.
Here you can configure Nexus systems, manage users, manage roles, manage tasks, view system RSS feeds, and view system logs, and this article introduces the most basic uses of Nexus.
2. Agent Maven Central Warehouse
By clicking on the repositories of the menu bar on the right, the main panel of the interface will display a list of all the warehouses and warehouse groups, and you will see their type, the Type field has group,hosted,proxy,virtual four types, We do not care about the virtual type here, we introduce the remaining three types:

    • Hosted, a local repository, usually we deploy our own artifacts to this type of warehouse.
    • Proxies, which are used to proxy remote public repositories, such as the MAVEN central repository.
    • Group, warehouse groups, which are used to consolidate multiple hosted/proxy warehouses, typically we configure MAVEN to rely on warehouse groups.

From this we know that we need to configure a proxy agent repository, in fact the Nexus has built-in central, but we need to do some configuration. Click Central in the warehouses list, such as

we will see several pages in the lower part of the main interface Browse Index,browse remote,browse storage,configuration,health Check, Routing,summary, we click Configuration to configure, you now need to care about the two configuration items: Remote Storage location is the repository address, for Central is http:// repo1.maven.org/maven2/; "Download remote Indexes" as the name implies is whether to download the remote index file, maven Central that the word defaults think false, This is to prevent a large number of nexus unconscious consumption of the central warehouse bandwidth (central warehouse has a large number of components, and its index files are very large). Here we need to set it to true and then click Save. After Nexus downloads the Central warehouse index file, we can search for all the components of the central repository locally. Shows the configuration we have just covered:

3. Add an agent warehouse
Here we give another example, we want to proxy Sonatype's public repository, whose address is: http://repository.sonatype.org/ content/groups/public/. Step below, on the repositories panel above, click Add, then select Proxy Repository, in the configuration section below, we fill in the following information: Repository id-sonatype;repository Name- Sonatype repository;remote Storage location-http://repository.sonatype.org/content/groups/public/. The rest of the remaining defaults, it is important to note that repository Policy, we do not want to proxy the snapshot widget, the reason is described earlier. then click Save. The configuration page is as follows:

4. Manage local maven warehouses
Nexus Pre-defined three local warehouses, releases,snapshots, and 3rd party. Each of the three warehouses has its own clear purpose. Releases is used to deploy our own release artifacts, snapshots is used to deploy our own snapshot artifacts, and the 3rd party is used to deploy third parties, some of which are JDBC drivers for Oracle, and we can't download them from a public repository. We need to deploy it to our own warehouses.
Of course you can also create your own local warehouse, similar to creating a proxy warehouse, click the Add button above the Repository panel, then select Hosted Repository, then enter the ID and name in the configuration panel below, Note that here we no longer need to fill out the remote repository address, Repository type is non-modifiable hosted, and about Repository Policy, you can choose release or snapshot according to your own needs,

5. Manage the Maven Warehouse group
The concept of a warehouse group in Nexus is not maven, and in Maven's view, whether you're hosted or proxy or group, To me is the same, I just according to Groupid,artifactid,version and other information to you to the component. To facilitate MAVEN configuration, the nexus can combine multiple warehouses, hosted or proxies into a group so that Maven relies on a group to use all the contents of the warehouse that the group contains. The
Nexus Pre-defines the "public repositories" and "public Snapshot repositories" two warehouse groups, which merge all predefined release warehouses by default, The latter merges all pre-defined snapshot warehouses by default. We created a warehouse named "Sonatype Repository" in the section earlier in this article and now merge it into the public repositories.
Click "Public repositories" in the Warehouse list and select "Configuration" tab below, in the configuration panel, "avaiable repositories" in the "Sonatype Repository "Drag to the left of the" Ordered group Repository ",

Create a warehouse group and create a proxy and hosted warehouse similar, here no longer repeat. Note that the format field needs to fill in "Maven2" and add the repositories you are interested in.
6. Search Widget
It is a depressing thing to click a link in a vast Maven repository and navigate the path to find the component of interest. Nexus provides component search based on Nexus-indexer, to search the repository, either Hosted,proxy, or group, you must confirm that the index file exists. This is especially important for agent warehouses, where some remote warehouses may not have indexes at all, so you cannot search for these agent warehouses. Some remote warehouses have large remote indexes, such as a central warehouse of around 70M, so it takes a lot of time to download the index for the first time, so expect the search results to be sure to see the following files:

Once your nexus has a local or remote repository index file, you can enjoy the Nexus Widget search feature. Whether you log in or not, you can use keywords for fuzzy search, such as I enter JUnit in the search box at the top of the left navigation bar, then click the Search button, and the right side will immediately display over 500 JUnit-related widget information. If you know more, you can also search by qualifying groupid,artifactid,version, click "Advanced Search" in the navigation bar, click the dropdown box in the upper left corner of all the pages on the right, and select "GAV Search". I enter junit:junit:4.4 here, and then enter:

Select a search result, "Artifact information" panel appears at the bottom of the page, you can click "Artifact" or "pom" to download the corresponding file, and the panel to the right shows a maven dependency configuration, you can directly copy the configuration to Maven In Pom, this is a very handy feature.
In addition, it is worth mentioning that the Nexus also supports Classname-based search, you just click on the search page in the upper right corner of the dropdown box, select "Classname Search", and then enter the class name, I will not repeat here.
7. Configure MAVEN to use Nexus
By default, MAVEN relies on a central repository in order to get Maven out of the box, but it is obviously wrong to do so, which can cause a lot of wasted time and bandwidth. Now that we've covered how to install and configure the Nexus in the previous section of the article, we need to configure MAVEN to use the local nexus to save time and bandwidth resources.
We can configure the repository in the Pom, but generally this is not a good practice, for the simple reason that you need to repeat the configuration for all MAVEN projects. So here I'm going to put the repository configuration in $user_home/.m2/settings.xml:

<settings xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi=" Http://www.w3.org/2001/XMLSchema-instance " xsi:schemalocation=" http://maven.apache.org/POM/ 4.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd ">  <localrepository>/users/chendaoqiu/.m2/repository</localrepository>    <interactivemode />    <usepluginregistry />    <offline />    <plugingroups />  <servers>        <server>          <ID>Nexus-releases</ID>          <username>Admin</username>          <password>Admin123</password>        </Server>        <server>          <ID>Nexus-snapshots</ID>          <username>Admin</username>         <password>Admin123</password>        </Server>      </Servers>      <mirrors />    <proxies />    <profiles>    <profile >            <ID>Dev</ID>            <repositories>                <repository>                    <ID>Nexus</ID>                    <URL>http://42.121.113.40:8981/nexus/content/groups/public/</URL>                    <releases>                        <enabled>True</enabled>                    </releases>                    <snapshots>                        <enabled>True</enabled>                    </Snapshots>                </repository>            </repositories>    </profile >    </Profiles>    <activeprofiles>        <activeprofile>Dev</activeprofile>  </activeprofiles></Settings>

We cannot insert elements directly into Settings.xml <repositories> , where we write a profile and add a profile and use <activeProfile> the element to automatically activate the profile. The Local-nexus warehouse here points to the "public repositories" warehouse Group in the Nexus we configured just now, that is, all the warehouses that the Warehouse group contains are available for us to use. In addition, we <release> have <snapshots> activated Maven's support for all types of warehouse component downloads through and elements, but you can also adjust the configuration, for example, by preventing Maven from downloading the snapshot widget from the Nexus.
With this configuration, maven downloads the widget from your Nexus server, and the speed and download from Central is not an order of magnitude.

8. Deploy Widgets to Nexus
The Nexus provides two ways to deploy artifacts, which you can upload directly from the UI, or you can configure MAVEN deployment artifacts.
8.1 Deployment via Nexus UI
Sometimes there is a jar file that you can't find from a public maven repository, but you can get the jar file (or even Pom) from the other, so you can deploy the file to the Nexus as part of the standard process. The steps are as follows:

8.2 Deployment through MAVEN
A more common use case is when the team is developing various modules of a project, in order for the module to be developed quickly for others to use, you will want to deploy the snapshot version of the artifacts to the Maven repository, others just need to add a dependency on the POM to your development module, You can always get the latest snapshot.
The following pom.xml configuration and settings.xml enable you to deploy artifacts through MAVEN automation:
Pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=" Http://www.w3.org/2001/XMLSchema-instance "xsi:schemalocation=" http://maven.apache.org/POM/ 4.0.0 http://maven.apache.org/maven-v4_0_0.xsd ">    ...<distributionmanagement>      <repository>        <ID>Nexus-releases</ID>          <name>Nexus Release Repository</name>          <URL>http://42.121.113.40:8981/nexus/content/repositories/releases/</URL>      </repository>      <snapshotrepository>        <ID>Nexus-snapshots</ID>        <name>Nexus Snapshot Repository</name>        <URL>http://42.121.113.40:8981/nexus/content/repositories/snapshots/</URL>      </snapshotrepository>    </distributionmanagement>...</Project>

Settings.xml

<settings xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi=" Http://www.w3.org/2001/XMLSchema-instance " xsi:schemalocation=" http://maven.apache.org/POM/ 4.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd ">...<servers>        <server>          <ID>Nexus-releases</ID>          <username>Admin</username>          <password>Admin123</password>        </Server>        <server>          <ID>Nexus-snapshots</ID>          <username>Admin</username>         <password>Admin123</password>        </Server>      </Servers>...</Settings>

Here we configure all of the snapshot version artifacts to be deployed to the Nexus Snapshots Warehouse, where all release components are deployed to the Nexus releases warehouse. Because the deployment requires logging in, we configure the user name and password corresponding to the repository ID in settings.xml.
Then, execute MVN deploy in the project directory, and you'll see that MAVEN deploys the project artifacts to the Nexus and browses to the Nexus repository to see the artifacts that were just deployed. When others build their projects, Maven looks for dependencies and downloads from the Nexus.

Configure Nexus Warehouses, deploy artifacts to nexus warehouses

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.