Nexus Repository with Mule 4

Mazhar Ansari
3 min readJul 28, 2020

In this blog we will try to learn how to use our own Nexus Repository with Mule 4.

What is Nexus OSS?

  • Nexus Repository OSS is an open source repository that supports many artifact formats, including Docker, Java™, and npm.
  • With the Nexus tool integration, pipelines in your toolchain can publish and retrieve versioned apps and their dependencies by using central repositories that are accessible from other environments.

Download Nexus OSS?

  • You can download Nexus OSS by registering here.
  • However I prefer the docker image which I downloaded from here.

Install and Run Nexus OSS:

If you downloaded the Windows version of Nexus OSS as a zip file.

  • Unzip Nexus OSS zip file in folder called <Nexus-Home>
  • Go to <Nexus-Home>
  • Open command prompt
  • Run command “nexus.exe /run

If you docker image on a unix system like it did.

  • docker pull sonatype/nexus3
  • mkdir /opt/docker/nexus-data && chown -R 200 /opt/docker/nexus-data
  • docker run -d -p 8081:8081 — name nexus -v /opt/docker/nexus-data:/nexus-data sonatype/nexus3
  • /opt/doker/nexus-data is custom directory i created for Mount a host directory as the volume
  • Open http://<your-host>:8081
Nexus OSS Main Page
  • Click on Sing in
  • Default username is admin and password is admin123

Configuring Nexus as a Maven repo:

To use Nexus as maven repo we need to create 4 repositories:

  • create a private (hosted) repository for our snapshots (maven-snapshots)
  • create a private (hosted) repository for our releases (maven-releases)
  • create a proxy repository pointing to Maven Central (maven-central)
  • create a group repository to provide all of these repos under a single URL (maven-public)

I suggest you create a new blob store for each new repo you want to create. That way, the data for every repo will be in a different folder in /nexus-data (inside the Docker container). But this is not mandatory for it to work.

The Docker Image I created already has all 4 repositories.

Repositories Browser

Configuring Nexus repos in Maven:

Update <User-Home>/.m2/settings.xml file

  • Add below lines under <servers>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
  • Add below lines under <mirrors>
<mirror>
<id>central</id>
<name>central</name>
<url>http://your-host:8081/repository/maven-group/</url>
<mirrorOf>*</mirrorOf>
</mirror>

Configure your Mule 4 project:

Mule 4 Project Structure

If you want only to download dependencies from Nexus, add below lines under project/repositories in project’s pom.xml.

<repository>
<id>maven-group</id>
<url>http://your-host:8081/repository/maven-group/</url>
</repository>
Mule 4 Project pom.xml

And if you also want to publish your project, add below lines under project/distributionManagement in project’s pom.xml.

<snapshotRepository>
<id>nexus-snapshots</id>
<url>http://your-host:8081/repository/maven-snapshots/</url>
</snapshotRepository>
<repository>
<id>nexus-releases</id>
<url>http://your-host:8081/repository/maven-releases/</url>
</repository>
Mule 4 Project pom.xml

Nexus, Maven and Mule 4 in Action:

Run below command from command project within Mule 4 project directory.

  • mvn deploy
Command prompt Image 1
Command prompt Image 2
  • You can see the jar in maven-snapshots repository
Repositories Browser for maven-snapshots

Note: as pom.xml version contains SNAPSHOT version that’s the reason it got uploaded in maven-snapshots repository. Else it will be uploaded in maven-releases repository.

--

--

Mazhar Ansari

I am seasoned Integration Architect with around 18+ yrs of exp. I have extensively worked on TIBCO and Mulesoft. Mainly in EAI, ESB, SOA, API and BPM projects.