Publishing to Nexus

I have a Nexus 3 server running on my internal network which I was using for testing some performance related things, which were relying on the Payara Micro feature that enables it to deploy artifacts from Maven coordinates directly.

What I wanted to do was to have my local machine know where to publish build artifacts, but not have the details of this server published in the publicly available pom file as it is not relevant to anyone except myself. Usually the server URLs are stored in the distributionManagement section of the POM file.

The logical place for this to be is in the user settings.xml file, but if you look at the definition for Servers here, there is no option to include the URL for the server.

The solution to this lies in the fact there are command line options which can be supplied to the deploy plugin to specify an alternative server. These can be defined in the properties for a profile in settings.xml.

Included here is my settings.xml file, with private values replaced. Also in this configuration are the settings to always use my nexus instance as a mirror for all Maven requests.

      <!--This sends everything else to /public -->
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <!--Configure repositories so they don't need to go in the pom file-->
    <!--make the profile active all the time -->


Note that prior to version 2.8 of the maven-deploy-plugin the only option available was “altDeploymentRepository”. This did not provide the flexibility to distinguish between the repository where snapshot and final releases would be published to.

By default my project was using version 2.7 of this plugin, so I had to update the pom.xml to include the newer plugin version.


With this in place, running mvn deploy will pick up the alternative deployment location and deploy the build artifacts.

[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ experiments ---
[INFO] Using alternate deployment repository nexus::default::

(Cut lots of logging)

Uploaded to nexus: (1.0 kB at 11 kB/s)
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  46.515 s
[INFO] Finished at: 2019-08-27T21:39:14+01:00
[INFO] ------------------------------------------------------------------------