Build your own maven private repository with nexus, and use nexusmaven private
Build your own maven private repository with nexus
When the nexus was just installed, the startup of the nexus failed. It started less than 1 minute and stopped automatically. Later I found the cause:
Java 6 Support EOL
Oracle's support for Java 6 ended in February 2013. Consequentially as of version 2.6 Nexus now requires a Java 7 JRE to run.
That is, 6 is not supported since 2.6.0, and jdk must be later than 7.
1. log on to nexus with the admin user
The download and installation of nexus are very simple, and there are many introductions on the Internet. This article will not be repeated. This section describes the configuration after installation.
The configuration of nexus needs to be completed using the admin role. The default password is admin123. after entering the nexus homepage, click the upper right corner to log on.
Then you can configure it in the menu on the left.
2. Configure proxy servers for nexus
Because this machine needs to access the Internet through a proxy, you must first configure the proxy Server in Administration --> Server.
After configuration, nexus can be connected to the central repository. If the private server's machine can be directly connected to the Internet, skip this step.
3. Configure repository
Configure in Views/Repositories --> Repositories
Three types of warehouses can be configured in nexus: proxy, hosted, and group.
Proxy is the proxy of the remote repository. For example, if a central repository proxy is configured in nexus, when the user requests an artifact from this proxy, the proxy will first find it locally. If it cannot be found, it will be downloaded from the remote repository and then returned to the user, which is equivalent to a transit function.
Hosted is the host repository. You can upload some of your components, deploy them to hosted, or manually upload the components to hosted. For example, if the oracle driver, ojdbc6.jar, cannot be obtained in the central repository, You need to manually upload it to the hosted.
A group is a repository group. It is unique to nexus and does not have this concept in maven. The purpose is to aggregate the above multiple warehouses and expose the Unified Address to the user, so that the user does not need to configure multiple addresses in the pom, as long as the group address is configured in a unified manner.
After the nexus is installed, some repository has been initialized and defined. After getting familiar with it, you can delete, add, and edit it on your own.
Click the Repository Path on the right to view the artifact list in the Repository. But pay attention to browser cache. Today, I found that the components have been updated, but cannot be seen in the browser. I thought it was a BUG, but it was actually cached by the browser.
4. Configure the proxy of the Central Repository
The most critical configuration may be the proxy configuration of the Central Repository, because most of the components are obtained through this proxy.
After nexus is installed, this proxy is preset. You need to change Download Remote Indexes to true so that nexus can Download the index from centralrepository, before artifact search can be used in nexus
There are some other public maven Repositories on the network. You can set the proxy in nexus in the same way, but not all maven repositories provide the nexus index. In this case, you cannot create an index.
5. Configure hosted repository
Generally, three hosted repository (3rd party, Snapshots, and Releases) are configured to save the third-party jar (such as ojdbc6.jar), the Snapshots in the project team, and the released version in the project team.
There is no special configuration here, just the Deployment Policy option. Generally, Snapshots is configured to allow, while Releases and 3rd party are set to disable.
6. Configure group repository
As mentioned above, the group is actually a virtual warehouse. By aggregating the physical warehouse (proxy and hosted), a unified address is exposed to the outside.
Note that the warehouse on the left will be aggregated. I made a mistake yesterday. I put all the warehouses on the right, and the result group is not aggregated. It is an empty warehouse...
VII. Configure the User Password
In Security --> Users configuration, right-click the deployment user, select Set Password, and Set a Password. This operation is done to prepare for subsequent submission.
8. configure settings. xml on the user's machine
After the preceding seven steps, the nexus configuration is complete. Next, you need to configure it on the development machine of each developer.
The configuration file is in % USER_HOME %/. m2/settings. xml
- <? Xml version = "1.0" encoding = "UTF-8"?>
- <Settings xmlns = "http://maven.apache.org/SETTINGS/1.0.0"
- Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
- Xsi: schemaLocation = "http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
- <Servers>
- <Server>
- <Id> nexus-snapshots </id>
- <Username> deployment </username>
- <Password> deployment </password>
- </Server>
- </Servers>
- <Mirrors>
- <Mirror>
- <Id> nexus </id>
- <Name> internal nexus repository </name>
- <Url> http: // 10.78.68.122: 9090/nexus-2.1.1/content/groups/public/</url>
- <MirrorOf> central </mirrorOf>
- </Mirror>
- </Mirrors>
- </Settings>
Only two elements <mirrors> and <servers> are configured here.
First, an image repository with the id of nexus is configured here. The address is the URL of the public group configured earlier, and then the image destination is central.
The super pom in maven is configured as follows:
- <Repositories>
- <Repository>
- <Id> central </id>
- <Name> Central Repository </name>
- <Url> http://repo.maven.apache.org/maven2 </url>
- <Layout> default </layout>
- <Snapshots>
- <Enabled> false </enabled>
- </Snapshots>
- </Repository>
- </Repositories>
- <PluginRepositories>
- <PluginRepository>
- <Id> central </id>
- <Name> Central Repository </name>
- <Url> http://repo.maven.apache.org/maven2 </url>
- <Layout> default </layout>
- <Snapshots>
- <Enabled> false </enabled>
- </Snapshots>
- <Releases>
- <UpdatePolicy> never </updatePolicy>
- </Releases>
- </PluginRepository>
- </PluginRepositories>
Therefore, when the required components (including jar packages and INS) cannot be found in the local maven project, they are obtained in central by default.
Therefore, the image repository We Just configured has a central id, so that requests from the local maven project to the central repository will be forwarded to the image repository, that is, the nexus private server we set.
Since other <repositories> and <pluginRepositories> elements are no longer configured in the project pom, you only need to configure a central mirror to prevent all Internet access. If other external network warehouses such as jboss repository are configured in pom, you can change <mirrorOf> *
As for the <servers> element, the reason is that when we upload the components in the project to the nexus repository, nexus will perform permission control, so we need to set the permission-related information here. Note that the <id> nexus-snapshotsid> here is consistent with the pom settings in the maven project.
Because we have blocked requests to the Internet repository, you do not need to configure the proxy server. to configure the proxy server, you can use the <proxies> element.
9. Configure the pom file of the maven Project
The simplified pom file is as follows:
- <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/xsd/maven-4.0.0.xsd">
- <ModelVersion> 4.0.0 </modelVersion>
- <GroupId> com. huawei. inoc. wfm. task </groupId>
- <ArtifactId> task-sla </artifactId>
- <Version> 0.0.1-SNAPSHOT </version>
- <Name> task-sla </name>
- <! -- Configure the remote repository for deployment -->
- <DistributionManagement>
- <SnapshotRepository>
- <Id> nexus-snapshots </id>
- <Name> nexus distribution snapshot repository </name>
- <Url> http: // 10.78.68.122: 9090/nexus-2.1.1/content/repositories/snapshots/</url>
- </SnapshotRepository>
- </DistributionManagement>
- </Project>
The <distributionManagement> element is configured here, And the <id> nexus-snapshots </id> element must be consistent with the configuration in the <servers> element in settings. xml described earlier.
The purpose of this configuration is to know which remote repository to deploy the generated component when maven deploy is executed. Note that the URL here is not the address of the public group:
Http: // 10.78.68.122: 9090/nexus-2.1.1/content/groups/public/
But the address of snapshots:
Http: // 10.78.68.122: 9090/nexus-2.1.1/content/repositories/snapshots/
However, in nexus, snapshots is also aggregated to the public group. Therefore, developer A submits the components to snapshots, and developer B can also obtain the components from the public group.
10. settings in eclipse
After the previous configuration, you can use the command line to perform maven operations. However, in actual development, the m2e plug-in of eclipse is generally used, so some additional configuration for eclipse is required.
In Preferences --> Maven --> User Settings, click Update Settings to load the changes we just made to settings. xml.
Then, in the Maven Repositories view, you can view the repository information.
As you can see, the central inherited from the Super pom is grayed out and unavailable. The mirrored by nexus later indicates that all requests to the repository will be forwarded to the mirror nexus.
11. directory structure of nexus
Nexus will be installed in % USER_HOME %/sonatype-work/nexus, with the following directory
The storage directory is the actual storage address of the component.