Maven-07-Using mvn command to upload dependencies to nexus private server

1. Goal

Upload the written code or dependent package to the mvn private server through the mvn command

2. Description

A single test environment is still used this time: windows+nexus+maven+IntelliJ IDEA 2020.3.2 x64

Three, general steps

1. Add nexus private server to maven configuration file

●Description: The maven configuration file varies according to the directory where you installed it. Generally, it is settings.xml in the conf folder under the maven root directory. Some are in C:\user\administrator\.m2\settings.xml (it may be like this)

1-2. Modify the Maven configuration file settings.xml file

1-3. In the <servers></servers> block of about 125 lines in settings.xml, add the following code

	<server>
      <id>xNexus-snapshots</id>
      <username>admin</username>
      <password>NexusServerPwd</password>
    </server>

Notes:

○ <id> --->You can write whatever you want. In the future, it must be consistent with the id value of snapshotRepository in the pom file of your java project.

○ <username> ---> write your nexus login account, the default is admin

○ <password> --->Write the password of your nexus login account

2. Add the private server address of nexus to the pom.xml file of your existing java project

2-1. Modify the pom.xml file of your java project

2-2. Add the following code under the secondary tree directory of pom.xml


  <distributionManagement>
       <repository>
	       <id>releases</id>
		   <url>http://10.100.100.60:8081/repository/maven-releases/</url>
       </repository>
	   <snapshotRepository>
	       <id>xNexus-snapshots</id>
		   <url>http://10.100.100.60:8081/repository/maven-snapshots/</url>
	   </snapshotRepository>
  </distributionManagement>

Note that this piece of code <distributionManagement> should be at the same level as <dependencies> in the pom file, and should also be at the same level as <groupId>.

Note that the value in <id>xNexus-snapshots</id> must be consistent with the id value of <server> in the maven configuration file settings.xml. Only in this way can your java project be associated with maven, and maven is associated with nexus.

Note that this time only the snapshots repository is used, and releases are not used, so the id of releases is temporarily unsure whether it is written in this way.

3. Test whether your java project can be uploaded to the snapshots warehouse of nexus normally

3-1. Use the windows command line tool to enter the root directory of your java project

3-2. Then execute the command under the windows command line

mvn deploy

4. Check the web page of nexus private server to see if you have received the dependency just uploaded

4-1. Log in to the private server of nexus, click [Browse] on the left, and then click [maven-snapshots] on the right

4-2. You can see that there is an extra beginning with com, which already shows that we uploaded successfully just now.

Why?

Because the groupId of the java project we just uploaded is com.kahn. Coming backwards.

4-3. Of course, you can also directly search for our project groupId in the search box on the web page of nexus.

For example, search for kahn.

-----------------kahn----------ok--------------------- -----February 17, 2021 22:30:18--------------------------------

Guess you like

Origin blog.csdn.net/xoofly/article/details/113838232