How to configure the nexus address when building with maven?
Description of the scene
When creating a Java build pipeline on the platform, it is not possible to configure the Nexus address. Follow the steps below to solve this problem.
Prerequisites
The Jenkins you are using must be the Jenkins tool created with the
The solution
-
In the left navigation bar, click DevOps Toolchain > Integrations.
-
Click the Jenkins tool card.
-
Click the Instance Name on the right side of Instance to enter the deployment details page.
-
In the Build Node area below, find the platform’s default build node Java.
-
Click Update Build node, turn on the Maven Settings file switch, refer to the following example, modify the relevant parameters, and add the code to the Content box:
Parameter Description <servers>Configure the authentication information of Nexus. <mirrors>Configure the redirected mirror repository address of profiles.profile.repositories.repository.idandprofiles.profile.pluginRepositories.pluginRepository.id.<profiles>Configures the dependency repository and plugin repository addresses, with profile.idas the unique identifier.<activeProfiles>Configures the active profile with profile.idto be enabled at startup.<?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"> <pluginGroups></pluginGroups> <proxies></proxies> <servers> <server> <id>nexus-releases</id> <username>admin</username> <password>Nexus12345</password> </server> <server> <id>nexus-snapshots</id> <username>admin</username> <password>Nexus12345</password> </server> </servers> <mirrors> <mirror> <id>nexus-releases</id> <mirrorOf>*</mirrorOf> <url>http://192.168.1.1:31108/repository/maven-public/</url> </mirror> <mirror> <id>nexus-snapshots</id> <mirrorOf>*</mirrorOf> <url>http://192.168.1.1:31108/repository/maven-public/</url> </mirror> </mirrors> <profiles> <profile> <id>nexus</id> <repositories> <repository> <id>nexus-releases</id> <url>http://192.168.1.1:31108/repository/maven-public/</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> <repository> <id>nexus-snapshots</id> <url>http://192.168.1.1:31108/repository/maven-public/</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus-releases</id> <url>http://192.168.1.1:31108/repository/maven-public/</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> <pluginRepository> <id>nexus-snapshots</id> <url>http://192.168.1.1:31108/repository/maven-public/</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>nexus</activeProfile> </activeProfiles> </settings> -
If the build command uses
mvn clean deploy, the dependency package will be uploaded to the Nexus that has been configured above. In addition to the above steps,distributionManagementneeds to be configured in thepom.xmlfile. The code example is as follows:Caution:
-
distributionManagementis included in theprojectparameter. -
When configuring the
releaselibrary andsnapshotslibrary, according to the Nexus Repository version policy configuration, the URLs of the two should be different, and thegrouptype of Repository (i.e. maven-public) cannot be used.
<project> <distributionManagement> <repository> <id>nexus-releases</id> <url>http://192.168.1.1:31108/repository/maven-releases/</url> </repository> <snapshotRepository> <id>nexus-snapshots</id> <url>http://192.168.1.1:31108/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement> </project> -
-
Configuration is now complete. If the suffix of the current project’s version number contains “-SNAPSHOT”, the pipeline will upload the artifact to the “snapshots” repository. Otherwise, it will be uploaded to the “releases” repository.