Manage libraries, artifacts and deliverables with Nexus Repository Manager OSS
The application development follows some basic pattern and one of the basic pattern is modularity, means a complex and big applications are split into different smaller subsets often termed as ‘module’. These modules arranged and form the final application. This modular design gives provides various benefits to the owner e.g. multiple teams can work independently and parallel to form application, reusability of module or component, easy bug fixing, maintenance, knowledge transfer, resource planning and so on. Additionally, there are a number of developers/contributors and organizations which provides open source reusable components like utilities, libraries, frameworks, platforms, packages and suites which can be used for rapid development and developers need to focus on the business logic only instead of focusing on building utilities, libraries and frameworks.
Once such components are developed, then need to store to a location so that when application use the components or assemble the components, it can be found easily. Therefore, development environment need to have a storage/repository where build components and be placed / published and build tools can easily integrate with it and use it when required.
To store, share and manage build components (also referred as artifacts) there is a proven solution to use artifact repository. There are many repository products are available like JFrog Artifactory, GitHub Package Registry, ProGet, Dist, MyGet, NPM, Bower, PyPI, Yarn, CloudRepo, Nexus Repository Manager etc. and often called Repository Manager.
Anyone of these given products can be used to setup development environment which provides artifact management. Artifact manager provides storage of artifacts along with:
- Version Management — It provide the effective version management and allows storage, sorting, filtering of artifacts’ version
- Availability & Retention — It ensures the artifacts availability and serving to each request for the artifact. After certain period/version/based on rule, artifacts need automated clean up.
- Access Control — It provides user management and access control to manage each repository and artifacts access can be controlled effectively
- Promotion — Once artifacts are published, it can be promoted to other artifacts based upon need
- Dependency Management — Some repository manager provides dependency analysis and management
- Release Stability — In many cases, with release additional metadata is also provided. It ensures that there is no change in distributable binary and metadata
- Efficient Build — It provides easy integration with build tools to manage artifacts
- Audit — Provides auditing feature of repository and artifact
Nexus Repository Manager OSS is most popular open source artifacts’ repository manager. Let’s discuss it in details in sub-sequent sections.
About Nexus Repository Manager OSS
Nexus Repository Manager OSS (in short Nexus Repo) is most popular and widely used artifact repository manager which provides below features:
- It provides centralized repository management where artifacts can be published as ‘Single Source of Truth’ and shared among the projects
- It provides effective storage and caching mechanism which provides optimized performance and reliability
- It provides basic features of a repository manager e.g. Access Control, Version Management, Availability & Retention, Dependency Analysis, Audit, Build and Efficiently Publish etc.
- It supports wide range of distributable e.g. Java/Maven — Jar, NPM, NuGet, Helm, Docker, P2, OBR, APT, GO, R, Conan etc. in form of binaries, assemblies and final outputs.
- Support of Java based build tools like Ant, Gradle, Maven and Ivy
- Compatible with tools like Hudson, Jenkins, Puppet, Chef, Docker etc.
Nexus Repo supports mainly three type of repositories for distributable (Maven, Npm, Nu, Helm, Docker etc.):
- Host — A host repository is the repository where artifacts published and stored the original copy of distributable [basically it is not the mirror image]
- Proxy — Proxy is used to create the mirror image. To understand it, let’s understand with example, suppose there is a maven central repository which contains various distributable artifacts. A Proxy can be created at organization level for maven central which creates a mirror for maven central by using cache at the first request from developer. On next, request it serves from cache. In this case, even if maven central disconnected, there will not be any impact.
- Group — It is just a group of repository
Nexus Repo provides a complete web application where it provides various screens which can be utilized for management purpose. It has following menus and options:
- Repository — It provides options to manage repositories, storage, cleanup, proprietary, routing rules and content selectors.
Repositories — Create and manage repositories
Blob Store — Create and manage Blob Storage where artifacts stored and cached
Cleanup Policy — Create and manage cleanup policy
Content Selectors — Create content selector based upon complex filters as where clause in SQL
Proprietary Repositories — Can be marked self-hosted repositories as proprietary repositories.
Routing Rules — Routing can be created and managed to route the request to specific repos based on configured rules
2. Security — It provides roles, user, access, certificates, ldap, privileges and realm management
Privileges — Provide create and manage privilege on different repositories and type of repositories. This will be linked to role to create roles.
Roles — Provides Roles creation and management for Role-based-access-management
User — User and Role mapping
Anonymous Access — Configure anonymous access policy
LDAP — Manage LDAP configuration
Realms — Enable/disable required realms
Certificate — Load and manage certificates
3. IQ Server Configuration — It provides IQ Server configuration (IQ Server is used for policy management)
4. Support — It provides configuration for support tools like Logging, Log Viewer, Status, Support Zip and System Information
Logging: Configure Logger and log level
Log Viewer: View Logs
Status: System health check and status
Support Zip: Creates a zip with useful support information for any issue investigation
System Information: About Nexus Repo and its components
5. System — It provides system administration and configuration like SMTP configuration, Tasks, Nodes, API, HTTP, Bundles etc.
API: Nexus Repo provides REST based APIs which can be used and custom screens can be developed
Bundles: Nexus Repo build of multiple modules known as bundles, this provide status of bundles
Capabilities: Nexus Repo provides additional capabilities e.g. audit, node identity, schedulers etc. it can be created and configured with this menu.
Email Server: Provides way to configure SMTP configuration.
HTTP: Configure HTTP/HTTPS related configuration
License: Option to import PRO license. Optional.
Nodes: View connected nodes, only works when cluster mode enabled.
Tasks: Create and manage tasks performed in Nexus Repo like cleanup task
Setup Nexus Repository Manager OSS
Although, most of the Nexus packages has internally package JRE, it may need to setup on machine. The Nexus Repo internally use Java and Jetty web server so compatible Java must be installed as prerequisite. Therefore, install JDK 8 or later version.
The Nexus Repo binary available for Unix, Windows and OSX platforms. It can be downloaded from URL: https://help.sonatype.com/repomanager3/product-information/download
Below are the steps to install Nexus Repo:
- Download the binaries as per underlying Operating System and extract it
- Below are basic details about directories
nexus-version -> bin — executable binaries / script
nexus-version -> etc — configuration files
Nexus Repo internally uses:
Integration configuration exists in /etc/fabric
Jetty server and configuration exists in /etc/jetty
Its bundles run on karaf and configuration can be found in /etc/karaf
Logback used for logging and configuration can be found in /etc/logback
To configure SSL, need changes in /etc/ssl
Nexus basic configuration are available in nexus-default.properties. It should not be modified. In case changes needed, create a file named ‘nexus.properties’ and place as /etc/nexus.properties
- To start Nexus run the below command on binary / script available in /bin directory
# For Linux
./nexus run# For Windows
It will launch application in couple of minute.
- Open browser and open URL http://localhost:8081/
Default user will be admin and a file path which contains the default will be given on screen. Use to login first time with that and then reset the password.
Note: If wanted to setup Nexus Repo on local and standalone mode, no need to change any configuration.
Create local hosted repository in Nexus
For different kind of artifacts (e.g. docker, java/maven, node-angular etc.), different repository to be created. Below are the steps to create repository in Nexus Repo:
- Open server ‘administration and configuration’ (just click gear icon)
- Click on Repository -> Repositories in Administration Section
- Click on Create Repository
It will open select recipe. Select docker for docker artifact, maven for maven/jar artifacts, npm for node-angular artifacts. For each recipe, there will be three types hosted, proxy and group. For local repository, select hosted
Provide the repository name and other details and click on create repository.
Note: We can go with all default by putting name only.
It will create repository and list as
- Click on copy button and copy the link of repository. This link will be used further in project pom.xml file so that when publish it, the artifact will be created in given repository.
Note: Similarly create repository for npm for Node-Angular project publish.
Java/Maven artifact with Nexus Repo
Case 1: Publish artifact in repository
To publish Java/Maven artifact, need to make distribution management entry in pom.xml
Change the URL under the URL tag and give repository URL copied while creating repository in Nexus Repo.
By default, repositories have read-only access therefore when publishing artifacts, it will give unauthorized error. To fix this, there are two ways, change the permission of repository and enable anonymous access.
The other approach is, provide the credential in maven-> conf -> settings.xml. Edit the settings.xml and add a server entry inside the <servers> tag and its id must be matching with distribution management repository id tag in pom.xml. E.g.
<!-- The ID must be matching with pom.xml’s -->
Now, go into maven project and perform below commands which compiles, build, publish package to Nexus Repo:
# Clean project
mvn clean# Compile project
mvn compile -Dmaven.test.skip=true# Package project
mvn package -Dmaven.test.skip=true# Install locally project
mvn install -Dmaven.test.skip=true# Publish artifact to Nexus Repo
mvn deploy -Dmaven.test.skip=true
Note: These maven command can be run in single command as well.
Case 2: Target Nexus Repo from Maven for artifacts
Open maven-> conf -> settings.xml. Edit the settings.xml and add mirror entry in <mirros> tag e.g.
To enable mirror, need to create provide and add profile in active profile list. To create profile add provide tag in <profiles>:
Now, make entry in <activeProfiles> tag to mark these profiles active:
Note: This configuration will work only when maven proxy repository configured into the Nexus Repo and anonymous access is enabled. In case anonymous access not enabled, then need to create a server entry provide username and password for the mirror entry with same id.
Node-Angular artifact with Nexus Repo
Case 1: Publish artifacts to Nexus Repo
To publish Npm artifact to Nexus Repo, first need to create hosted type Npm repository in Nexus Repo and copy URL.
Now change Npm project’s package.json and make it private:
Add user in Npm by using below command:
npm adduser --registry http://localhost:8081/repository/mynpmrepo/ --always-auth
It will ask for username and password on console. Provide username and password to complete add user process in Npm.
Build the project and then run below command to publish artifact to Nexus Repo:
npm publish --registry http://localhost:8081/repository/mynpmrepo/
Case 2: Target Nexus Repo from Npm
To set the Nexus Repo mirrors in Npm. There are two ways: by using command, by creating or editing .npmrc file in user local directory
npm config set proxy http://admin:admin@localhost:8081/repository/mynpmproxyrepo/
Note: Here admin:admin is username and password
If using unsecure registry (with HTTP only not HTTPS), need to enable insecure registry by below command:
npm config set strict-ssl=false
If want to change manually with .npmrc file then create a file in user directory. If .npmprc file is already available then edit it and provide details like:
Now, run Npm commands, it will use configured proxy registry.
Note: Before configuring registry proxy in Npm, first create Proxy type Npm recipe repository in Nexus Repo. Additionally, anonymous access provided on repository. No need to add username and password.
Here, we have given use case with Java/Maven and Npm-Angular. If need more use case with other supported programming languages and build tool. Please let us know, we will add.
Repository Manager is essential tool for the development environments to enable a protected and secure development environment where all public/central repositories must be access via mirroring from repository manager.
The deliverable must also be published so it will be available to other teams who are working on project and use the deliverable as reusable module. A perfect version control, access management and integration with build tools are also required.
Nexus Repository Manger OSS (also referred as Nexus Repo) is most popular and widely used for repository management in organizations. It is open source and free for uses. However, PRO version is also available from Sonatype which provides additional features on top of Nexus Repo.
About the Author
Sandeep Kumar holds Master of Computer Application degree working as Java developer having 10+ years of working experience. He has experience design and development of enterprises applications in domains like education, content, laboratory, and banking; got various appreciation for his solutions including spot appreciation for Glassfish to JBoss migration project. He secured Google Cloud Developer certificate and participated into OCI trainings. He is a part of HCL-ERS platform as Sr. Lead developer.