Publish third-party maven packages to the central repository

Deploy

Command line

You can use command like this:

1
mvn deploy:deploy-file -Dmaven.test.skip=true -Dfile=D:\MvnProject\service-mvn-1.0.0.jar -DgroupId=pri.roy.mvn.test -DartifactId=mvn-api -Dversion=1.0.0-SNAPSHOT -Dpackaging=jar -DrepositoryId=roy_privrepository_snapshots -Durl=http://10.4.71.144:9090/repository/roy_privrepository_snapshots/

Parameter description:

1
2
3
4
5
6
7
8
-Dmaven.test.skip=true                              //Skip compilation and testing
-Dfile=D:\MvnProject\service-mvn-1.0.0.jar //Absolute path of the jar pakcage file
-DgroupId=pri.roy.mvn.test //gruopId--Coordinate of pom
-DartifactId=mvn-api //artifactId--Coordinate of pom
-Dversion //Version
-Dpackaging //Packaging type, jar / war
-DrepositoryId //ID of the remote library server
-Durl //Url of the remote library server

pom.xml

First, we need configure maven’s settings.xml file, to add account and password for Nexus:

1
2
3
4
5
6
7
<servers>
<server>
<id>id of profile</id>
<username>username of nexus, must have administrator privileges</username>
<password>password of nexus</password>
</server>
</servers>

Then, in the pom.xml file, add the version information of the component package(inside the node of project):

1
2
3
<groupId>com.myhexin</groupId>
<artifactId>library</artifactId>
<version>1.3</version>

Next, in the pom.xml file, add the relevant configuration information(inside the node of project):

1
2
3
4
5
6
7
8
9
10
11
12
13
<distributionManagement>
<repository>
<id>Intranet Private Repository</id>
<name>Internal Releases</name>
<!-- When deploying,you must chose a "hosted" type of repository -->
<url>http://x.x.x.x:port/nexus/content/repositories/b2c-web/</url>
</repository>
<snapshotRepository>
<id>Intranet Private Repository</id>
<name>Internal Snapshot</name>
<url>http://x.x.x.x:port/nexus/content/repositories/b2c-web/</url>
</snapshotRepository>
</distributionManagement>

Finally, execute the release command:

1
mvn deploy

Issue

When the deploy command is executed, a 400 status code is returned.

Maybe your account or password is wrong.

Deployment failed.

Check if the same version of the package already exists in the repository.

The difference between defferent types of repositories.

In Nexus Repository Manager 3 (NXRM3) there are three repository types—proxy repositories, hosted repositories, and repository groups—all using a number of different repository formats. Understanding the available repository types helps define what is needed within your organization for a successful NXRM3 implementation.

For example, if your team needs to access public repositories, you’ll want to create proxy repositories. If your team has components that aren’t public, but are used by others in your development organization, then creating a hosted repository is the way to go. If you have multiple repositories that would be easier to access from a single URL, then creating a group repository fits that need.

With these examples in mind, you can see that creating and managing repositories is an essential part of your Nexus Repository Manager configuration because it allows you to expose more components to your users.