Setting Up a Nexus Mirror for Maven
You are viewing documentation for a release that is no longer supported. The latest supported version of version 3 is [3.11]. For the most recent version 4, see
While developing your application with Java and Maven, you will most likely be building many times. In order to shorten the build times of your pods, Maven dependencies can be cached in a local Nexus repository. This tutorial will guide you through creating a Nexus repository on your cluster.
This tutorial assumes that you are working with a project that is already set up for use with Maven. If you are interested in using Maven with your Java project, it is highly recommended that you look at their guide.
In addition, be sure to check your application’s image for Maven mirror capabilities. Many images that use Maven have a environment variable that you can use to simplify this process. If it does not have this capability, read to configure your build properly.
Furthermore, make sure that you give each pod enough resources to function. You may have to edit the pod template in the Nexus deployment configuration to request more resources.
Download and deploy the official Nexus container image:
-
The output should resemble:
NAME HOST/PORT PATH SERVICES PORT TERMINATION
nexus nexus-myproject.192.168.1.173.xip.io nexus 8081-tcp
Confirm that Nexus is running by navigating your browser to the URL under HOST/PORT. To sign in to Nexus, the default administrator username is admin, and the password is admin123.
This is a good time to set up . These will periodically check to see that Nexus is running properly.
Adding Persistence to Nexus
If you do not want persistent storage, continue to . However, your cached dependencies and any configuration customization will be lost if the pod is restarted for any reason. |
Create a persistent volume claim (PVC) for Nexus, so that the cached dependencies are not lost when the pod running the server terminates. PVCs require available persistent volumes (PV) in the cluster. If there are no PVs available and you do not have administrator access on your cluster, ask your system administrator to create a Read/Write Persistent Volume for you.
Otherwise, see Persistent Storage in OKD for instructions on creating a persistent volume.
$ oc volumes dc/nexus --add \
--name 'nexus-volume-1' \
--claim-name 'nexus-pv' \
--claim-size '1G' \
--overwrite
This removes the previous emptyDir volume for the deployment config and adds a claim for one gigabyte of persistent storage mounted at /sonatype-work
, which is where the dependencies will be stored. Due to the change in configuration, the Nexus pod will be redeployed automatically.
To verify that Nexus is running, refresh the Nexus page in your browser. You can monitor the deployment’s progress using:
The next steps demonstrate defining a build that uses the new Nexus repository. The rest of the tutorial uses with wildfly-100-centos7 as a builder, but these changes should work for any project.
The example builder image supports as part of its environment, so we can use this to point our builder image to our Nexus repository. If your image does not support consuming an environment variable to configure a Maven mirror, you may need to modify the builder image to provide the correct Maven settings to point to the Nexus mirror.
$ oc new-build openshift/wildfly-100-centos7:latest~https://github.com/openshift/jee-ex.git \
-e MAVEN_MIRROR_URL='http://nexus.<Nexus_Project>:8081/nexus/content/groups/public'
$ oc logs build/jee-ex-1 --follow
Replace <Nexus_Project>
with the project name of the Nexus repository. If it is in the same project as the application that is using it, you can remove the <Nexus_Project>.
. .
In your web browser, navigate to http://<NexusIP>:8081/nexus/content/groups/public to confirm that it has stored your application’s dependencies. You can also check the build logs to see if Maven is using the Nexus mirror. If successful, you should see output referencing the URL .