Building and managing projects with Maven is a great pleasure, and we can download the required artifacts from the MAVEN central repository (artifact), but in practice we need to build a MAVEN local agent repository for a variety of reasons, such as: inconvenient access to the public network, saving bandwidth and time, Manage your own shared artifact and more. The local geodatabase is my own name, in order not to be confused with the local repository below.
The process of getting the build is as follows: When a user builds a project using MAVEN, it is first obtained directly from the local repository, and if the local repository does not, it will first attempt to download artifacts from the remote repository to the local repository, and then use the artifacts of the local warehouse, based on the Setting.xml settings. If the remote repository set up by Setting.xml is the local agent repository, the local agent warehouse tries to get from its own library first, and if it is not downloaded from the remote repository (such as a central warehouse) to the local repository.
Nexus is an excellent MAVEN warehouse manager, also provides a powerful warehouse management function, component search function, it is based on rest, friendly UI is a ExtJS rest client, it occupies less memory, based on a simple file system rather than a database. These advantages make it increasingly the most popular MAVEN warehouse manager. This article uses Nexus to build a local agent repository.
Download and install
Nexus official Download Address: Http://www.sonatype.org/nexus/go, currently the latest version is 2.7.2.
Nexu installation is very easy because it embeds the jetty, as long as the JRE can be saved to run directly. Extracting the NEXU package will get two directories nexus-2.7.2-03 and sonatype-work,sonatype-work are the default warehouse directories. Running, installing is using the Nexus-2.7.2-03/bin/nexus.bat file, how it is used:
Usage:nexus.bat {Console:start:stop:restart:install:uninstall} where console is run as console, install is Windows service hosting, U Ninstall is downloading Windows service, start is running Windows service, stop is stopping Windows service, restart is restarting Windows service.
Nexus default port is 8081, can be modified in Nexus-2.7.1-01/conf/nexus.properties, after startup can be accessed through the address: Http://localhost/:8081/nexus. The interface is as follows:
Manage Warehouses
The management warehouse needs to log in first, the default login username/password is admin/admin123. Once you're signed in, you'll see the admin item in the left column menu.
Here, you can manage warehouses, configure Nexus Systems, manage tasks, manage users, roles, permissions, view RSS feeds for your system, manage and view system logs, and more. Set up a Nexus proxy on the public network
If your local agent warehouse server does not have public access, Nexus has left you the way to use the proxy, click "Server" on the right menu and find it on the right:
Add your proxy server. Warehouse Management
By clicking on the repositories in the left navigation bar, the main panel of the interface will display a list of all the warehouses and warehouse groups, and you will see that the value of their type field is group,hosted,proxy,virtual. Here we do not care about virtual, only introduce the next three types: hosted, the local agent warehouse, usually we will deploy their own artifacts to this type of warehouse. Proxy, the remote repository of 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. How to manage, add and so on, the Nexus is written very clearly, I will not repeat.
Modifying the Setting.xml configuration maven repository
The default is to use a central repository after Maven is installed, so that Maven can be out of the box. The default local repository address for MAVEN is ${user.home}/.m2/repository. In other words, a user will have a local repository. You can also customize the location of the local warehouse and modify the ${user.home}/.m2/settings.xml.
First you need to modify mirrors
<mirrors> <!--Mirror | Specifies a repository mirror site to use instead of a given repository. The Repository that | This mirror serves have an ID, that matches, the mirrorof element of this mirror. IDs is used | For inheritance and direct lookup purposes, and must is unique across the set of mirrors. | -<mirror> <id>nexusc</id> <mirrorOf>*</mirrorOf> <name>nexus</name > <url>http://localhost:8081/nexus/content/groups/public/</url> </mirror> </mirrors> MAVEN also needs to install some plug-in packages when executing the MAVEN command, which also points to the address of the local agent repository, modified as follows:
<profile> <id>jdk-1.4</id> <activation> <jdk>1.4</jdk> </activation> < repositories> <repository> <id>nexus</id> <name>local private nexus</name> <url >http://localhost:8081/nexus/content/groups/public/</url> <releases> <enabled>true</ enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </ repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id > <name>local Private nexus</name> <url>http://localhost:8081/nexus/content/groups/public/ </url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled >false</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile >
For more setting.xml field explanations please see here.
Now you can build a MAVEN project with a local repository and embark on a pleasant build journey.
deploy artifacts to Nexus
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:
Click "Repository" in the left navigation bar, select a warehouse in the list of warehouses on the right, such as "3rd party", then tab at the bottom of the page to select "Artifact Upload Artifact (s)", you will see the widget upload interface. Select the widget you want to upload and specify the pom, (or manually write Gav, etc.), and then click Upload, and the widget is deployed directly to the Nexus "3rd party" warehouse.
Deploy with 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> ... <distributionManagement> <repository> <id>nexus-releases</id> <name >nexus Release repository</name> <url>http://localhost:8081/nexus/content/repositories/releases/ </url> </repository> <snapshotRepository>