Create Maven private server for Nexsus

Refer to Xiaobai to build Maven server for Nexus

Maven configuration using Nexus private server

Maven configures the dependency mode for private server download

Maven configures private server downloads in two ways

  • Setting.xml: This file configures the global schema
  • Pom.xml: This file is configured in project proprietary mode

If pom. XML and setting. XML are configured at the same time, pom. XML prevails

Setting. XML file configuration

Location: D: \ backend \ apache maven – 3.8.3 \ conf \ setting XML

At this point, there is no need to configure the POM.xml file, and you can use the private server to download the JAR dependencies

Configure the private server mirroring
<mirrors> <! -- mirror | Specifies a repository mirror site to use instead of a given repository. The repository that | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. | <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human  Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror> --> <! -- <mirror> <id>maven-default-http-blocker</id> <mirrorOf>external:http:*</mirrorOf> <name>Pseudo repository to mirror External Repositoris using HTTP.</name> <url>http://0.0.0.0/</url> <blocked>true</blocked> </mirror> --> <mirror> <! -- Unique identifier of the mirror. Id is used to distinguish between mirror elements. --> <id>nexus-releases</id> <! --* means to access any repository using our private server --> <mirrorOf>*</mirrorOf> <! -- The URL of the image. The build system will use this URL in preference to the default server URL. -- > < url > http://192.168.57.128:9081/repository/maven-public/ < / url > < / mirror > < mirror > < id > nexus - snapshots < / id > < mirrorOf > * < / mirrorOf > < url > http://192.168.57.128:9081/repository/maven-snapshots/ < / url > < / mirror > < / mirrors >Copy the code

The URL of the image can be copied directly from the copy button in the page

Configure to download jar packages from private servers
<! -- profiles | This is a list of profiles which can be activated in a variety of ways, and which can modify | the build process. Profiles provided in the settings.xml are intended to provide local machine- |  specific paths and repository locations which allow the build to work in the local environment. | | For example, if you have an integration testing plugin - like cactus - that needs to know where | your Tomcat instance is installed, you can provide a variable here such that the variable is | dereferenced during the build process to configure the cactus plugin. | | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles | section of this document (settings.xml) -  will be discussed later. Another way essentially | relies on the detection of a system property, either matching a particular value for the property, | or merely testing its existence. Profiles can also be activated by JDK version prefix, Where a value of '1.4' | took activate a profile when the build is executed on a JDK version of '1.4.2 _07'. | the Finally, the list of active profiles can be specified directly from the command line. | | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact | repositories, plugin repositories, and free-form properties to be used as configuration | variables for plugins in the POM. | |--> <profiles> <! -- profile | Specifies a set of introductions to the build process, to be activated using one or more of the | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/> | or the command line, profiles have to have an ID that is unique. | | An encouraged best practice for profile identification is to use a consistent naming convention | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc. | This will make it more intuitive to understand what the set of introduced profiles is attempting | to accomplish,  particularly when you only have a list of profile id's for debug. | | This profile example uses the JDK version to trigger activation, And provides a JDK-specific repo. <profile> < ID > JDK-1.4 </ ID > <activation> < JDK >1.4</ JDK > </activation> </activation> < repository > < id > jdk14 < id > < name > repository for JDK 1.4 builds < / name > < url > http://www.myhost.com/maven/jdk14 < / url > <layout>default</layout> <snapshotPolicy>always</snapshotPolicy> </repository> </repositories> </profile> --> <! -- | Here is another profile, activated by the system property 'target-env' with a value of 'dev', | which provides a specific path to the Tomcat instance. To use this, your plugin configuration | might hypothetically look like: | | ... | <plugin> | <groupId>org.myco.myplugins</groupId> | <artifactId>myplugin</artifactId> | | <configuration> | <tomcatLocation>${tomcatPath}</tomcatLocation> | </configuration> | </plugin> | ... | | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to | anything, you could just leave off the <value/> inside the activation-property. | <profile> <id>env-dev</id> <activation> <property> <name>target-env</name> <value>dev</value> </property> </activation> <properties> <tomcatPath>/path/to/tomcat/instance</tomcatPath> </properties> </profile> --> <profile> <! -- Profile id--> <id> Nexus </ ID > <repository> <! > < ID > Nexus - Releases </ ID > <! -- The repository address, which is the address of the Nexus repository group --> < URL >http://nexus-releases</ URL > <releases> <! - whether to download the releases component - > < enabled > true < / enabled > < / releases > < snapshots > < enabled > true < / enabled > < / snapshots > < / repository > <repository> <id>nexus-snapshots</id> <url>http://nexus-snapshots</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <! <pluginRepository> <pluginRepository> -- The id of the plugin repository cannot be duplicated. > <id> Nexus -Releases </ ID > <url>http://nexus-releases</ URL > < Releases > <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> <pluginRepository> <id>nexus-snapshots</id> <url>http://nexus-snapshots</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <! -- Activate Profile --> <activeProfiles> <activeProfile> Nexus </activeProfile> </activeProfiles>Copy the code

Pom.xml file configuration

If you have configured pom.xml, use pom.xml

<repositories> <repository> <id>maven-nexus</id> <name>maven-nexus</name> The < url > http://10.172.0.201:8081/repository/maven-public/ < / url > < releases > < enabled > true < / enabled > < / releases > < snapshots > <enabled>true</enabled> </snapshots> </repository> </repositories>Copy the code

3. Configure Maven to connect private server package upload project

First, modify the setting. XML file and specify the user name and password for Releases and snapshots server

<servers> <! -- server | Specifies the authentication information to use when connecting to a particular server, identified by | a unique name within the system (referred to by the 'id' attribute below). | | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are | used together. | <server> <id>deploymentRepo</id> <username>repouser</username> <password>repopwd</password> </server> --> <! -- Another sample, using keys to authenticate. <server> <id>siteServer</id> <privateKey>/path/to/private/key</privateKey> <passphrase>optional; leave empty if not used.</passphrase> </server> --> <! > <server> < ID > Releases releases</ ID > <username>account</username> <password>password</password> </server> <server> <id>snapshots</id> <username>account</username> <password>password</password> </server> </servers>Copy the code

Second, add the distributionManagement node to the project’s POM.xml file

Note: The repository ID needs to be the same as the server ID name in step 1

<! -> <distributionManagement> <repository> < ID > Releases </ ID > <name> Releases </name> The < url > http://192.168.57.128:9081/repository/personal-maven-releases/ < / url > < / repository > < snapshotRepository > < id > snapshots < id > < name > snapshots < / name > < url > http://192.168.57.128:9081/repository/peronsal-maven-snapshots/ < / url > </snapshotRepository> </distributionManagement>Copy the code

I created two new Nexus repositories myself: Personal-Maven-Releases and PeronSal-Maven-snapshots

Create steps (see the default Maven-Releases and Maven-snapshots, both of which are hosted) :

Create personal-Maven-Releases: Click Create Repositories, select Maven2 (Hosted), name it Personal – Maven-Releases,Version Policy Release, and Deployment Policy Allow Redeploy, Blob Store Select defalut and save.

Create personal-maven-snapshots. Click Create Repositories, select Maven2 (Hosted) and call it Personal-Maven-snapshots,Version Policy Snapshot and Deployment Policy Allow Redeploy, Blob Store Select defalut and save.

Step 3: Publish

Note here: if you have @test in your project, the command to run is MVN clean deploy-dskiptests

mvn clean deploy -DskipTests
Copy the code

Log in to the Nexus and check that the repository already has its dependencies.

Note the following points:

  • If a project version contains -snapshot at the end of it, it is reported to the snapshots repository
  • If the project version number ends with -Releases or nothing at all, then it RELEASES to the RELEASES official repository, right

Upload the third-party JAR package

To be continued

Q&A

status: 401 Unauthorized

The reason:

  • Pom. In the XMLdistributionManagementtherepositoryIs inconsistent with the server ID in setting. XML
  • The account and password permission of the server are insufficient. Procedure

Status: 400 Repository version Policy: RELEASE does not allow version: 1.0-20211205.034457-1

The reason:

  • The Deployment policy for the repository is not set to Allow Redeploy
  • The type of warehouse and in pom.xml< version > 1.0 - the SNAPSHOT < / version >The type is inconsistent. Here it isSNAPSHOT, so the warehouse type should be set to Snapshot