“This is the 11th day of my participation in the Gwen Challenge in November. See details: The Last Gwen Challenge in 2021”

What is Nexus

When I first started using Maven, I always heard the word Nexus, now Maven, now Nexus. Why is it always mentioned with Maven?

Maven is an excellent build tool, dependency management tool, project information management tool, when implementing dependency management, through the pom.xml

<dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> The < version > 2.1.0 < / version > < / dependency >Copy the code

To pinpoint the appropriate Java class library. In this process we need to move fromwarehouseTo find the corresponding JAR package to introduce into our project, thus we solved the cooperative developmentIncreased dependency, version inconsistency, version conflict, and bloated dependencyWait for a problem.Maven hasLocal repositoryandRemote warehouseWhen Maven looks for an artifact based on coordinates, it first looks at the local repository. If the artifact exists in the local repository, it uses it directly. If the component does not exist in the local repository, or if a newer version of the component is needed, Maven will go to the remote repository, find the required component, and download it to the local repository for reuse.

Now, as I’m sure you understand,Nexus is a remote repository.Is also a kind of private service.

SNAPSHOT SNAPSHOT version. In Maven, SNAPSHOT version represents the development version before the official release. In POM, x.y-snapshot is used.

Maven RELEASE stands for stable RELEASE, unchange, unchangeable. In Maven, SNAPSHOT and RELEASE are different in terms of policy. SNAPSHOT updates frequently from remote repository to local repository, depending on your configuration; RELEASE will only be downloaded to the local repository for the first time, and then will be directly searched from the local repository.

2. Build Maven private server with Nexus3

Maven private server nexus3.x build and Maven private server Nexus3.x build in Windows

3. IDEA package and upload to Nexus3 private server

1. Configure settings. XML under.m2

First, this file is added to the.m2 file of the current device logged-in user on the system diskDid not go online copy a good configuration, their configuration is easy to make mistakes

->settings.xml<-

<servers>
	<server>
	      <id>nexus</id>
	      <username>admin</username>
	      <password>admin123</password>
     </server>
     <server>
	      <id>maven-snapshots</id>
	      <username>admin</username>
	      <password>admin123</password>
     </server>
      <server>
	      <id>maven-releases</id>
	      <username>admin</username>
	      <password>admin123</password>
     </server>
     <server>
		<id>rdc-releases</id>
		<username>xxxxxxxxx</username>
		<password>xxxxx</password>
	</server>
	<server>
		<id>rdc-snapshots</id>
		<username>xxxxxxxxx</username>
		<password>xxxx</password>
	</server>
</servers>


Copy the code

2. Configure POM.xml in the IDEA project

 <distributionManagement>
    <repository>
      <id>nexus</id>
      <name>nexus</name>
      <url>http://xxxx:port/repository/maven-snapshots/</url>
    </repository>

    <snapshotRepository>
      <id>maven-snapshots</id>
      <name>maven-snapshots</name>
      <url>http://xxxx:port/repository/maven-snapshots/</url>
    </snapshotRepository>
  </distributionManagement>
Copy the code

The id in the tag corresponds to the ID in the first server. The url value can be written directly here or in the Settings file as shown below. Name can be customized ->settings.xml<-

<profile>
	<altReleaseDeploymentRepository> http://xxxx:port/repository/maven-snapshots/ </altReleaseDeploymentRepository>
	<altSnapshotDeploymentRepository> http://xxxx:port/repository/maven-snapshots/</altSnapshotDeploymentRepository>
</profile>
Copy the code

Again, change the pom.xml above to the following format

<distributionManagement>
    <repository>
      <id>nexus</id>
      <name>nexus</name>
      <url>${altReleaseDeploymentRepository}</url>
    </repository>

    <snapshotRepository>
      <id>maven-snapshots</id>
      <name>maven-snapshots</name>
      <url>${altSnapshotDeploymentRepository}</url>
    </snapshotRepository>
  </distributionManagement>
Copy the code

3. Configure the upload address to copy the address from the private server

<profile> <! Dev </id> <repository> <repository> <! <id> Nexus </ ID > <! - warehouse address, that is, the nexus warehouse group address - > < url > http://localhost:8081/nexus/content/groups/public/ < / url > <! Download dependency dependency --> < Dependency dependency > < Enabled >true</enabled> </releases> <! Snapshots --> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <! <pluginRepository> <pluginRepository> -- The id of the plugin repository cannot be duplicated. -> <id> Central </ ID > <name>Nexus Plugin Repository</name> <url>http://central</ URL > < Releases > <enabled>true</enabled>
            </releases>
            <snapshots>
               <enabled>true</enabled>
            </snapshots>
		</pluginRepository> 
	</pluginRepositories> 
</profile>

Copy the code

4. Other Configurations (ignore)

For example, configure ali mirror, map Ali central warehouse (download JAR package faster)

<mirrors>
   <mirror>
    <id>alimaven</id>
    <name>aliyun maven</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    <mirrorOf>central</mirrorOf>       
  </mirror>
</mirrors>

Copy the code

Configure the local repository (no networking using jar packages)

<localRepository>E:\maven_repository</localRepository>
Copy the code

5. Settings.xml fully configured (source network, for reference only)

<? 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"> <! D:\mvn_repo\repository</localRepository> <! > <pluginGroups> </pluginGroups> </proxies> <servers> <server> <! -- id, which corresponds to the id of the distributionManagement configuration in the project plom.xml --> <id>maven-releases</id> <! <username>admin</username> <! -- Nexus login password --> <password> Admin123 </password> </server> <server> <! <id> moon-snapshots </id> <! <username>admin</username> <! -- Nexus login password --> <password> Admin123 </password> </server> <! -- Configure the interceptor mirror login username and password. It will block all requests to the address specified by the mirror to download the JAR package. If you only need to download the JAR package from the private server, only need to configure this item. -- id, mirror id --> <id>nexus</ ID > <username>admin</username> <password> Admin123 </password> </server> </ Servers > <! The following configuration is common for downloading JAR packages --> <mirrors> <! <id>nexus</id> <mirrorOf>* The < url > http://192.168.65.129:8081/repository/maven-public/ < / url > < / mirror > < / mirrors > < profiles > < profile > <! ActiveProfiles --> <id> Nexus </id> <! <repository> <repository> <! --> <id>central</id> <! <name>Nexus</name> <! --> <url>http://central</url> <! Supporting releases --> < Releases > < Enabled >true</enabled> </releases> <! Snapshots --> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <! PluginRepository <id> Central </ ID > <name>Nexus Plugin Repository</name> <url>http://central</url> <releases> <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> <! --> <properties> < ReleaseRepository > http://192.168.65.129:8081/repository/maven-releases/ < / ReleaseRepository > < SnapshotRepository > http://192.168.65.129:8081/repository/maven-snapshots/ < / SnapshotRepository > < / properties > < / profile >  </profiles> <! -- Select the profile to use --> <activeProfiles> <activeProfile> Nexus </activeProfile> <! -- <activeProfile>rdc</activeProfile>--> </activeProfiles> </settings>Copy the code

6. Package and upload IDEA

The idea package is used. During the package, the poM file determines whether the SNAPSHOT version is a SNAPSHOT version or a release version according to the version in the poM file. 0.0.1-SNAPSHOT Indicates the SNAPSHOT version if the SNAPSHOT is added, and SNAPSHOT indicates the release version if the SNAPSHOT is deleted. When uploading to a private server, the server automatically determines which warehouse to upload to according to version

Note: Maven-plugin must be removed from the POM file of the project during packaging. Otherwise, boot-INF folder will be generated after packaging. This will cause jar package can be downloaded after uploading to private server, but the error cannot be found when using The Times package

The < version > 1.1 - the SNAPSHOT < / version > < build > < / build >Copy the code

Then clean after deployseeBUILD SUCCESSThe prompt is successful, you can view it on your private server