If you're new to repository management with Nexus Repository Manager 3,  use this guide to get familiar with configuring the application as a dedicated proxy server for Maven and npm builds. To reach that goal, follow each section to:

When you complete the steps, the components will be cached locally to your repository manager. After meeting the requirements to run the repository manager, it should take approximately 15 minutes to proxy Maven and npm with the code snippets below.

Requirements

Before you can set up the proxy server for Maven and npm, you’ll need to install and configure the following external tools for the repository manager:

Part 1 - Installing and Starting Nexus Repository Manager 3

  1. Create an installation directory in your desired location.
  2. Download the most recent repository manager for your operating system.
  3. If the file is downloaded to a location outside the installation directory, move it there.
  4. Unpack the .tar.gz or .zip file in its new location. Both an application (i.e. nexus-<version>) and data directory (i.e. ../sonatype-work/nexus3) are created after extraction.
  5. Go to the application directory which contains the repository manager file you need to start up.
  6. In the application directory, run the startup script launching the repository manager:
    Wait until the log shows the message Started Sonatype Nexus.
  7. Open your browser and type http://localhost:8081/ in your URL field.
  8. From the user interface click Sign In, which generates a modal to enter your credentials.
  9. Log in with the default credentials  admin / admin123 , the respective username / password.
  10. Change the default password!

Part 2 - Proxying Maven and npm Components

When you proxy components the repository manager acts as a local intermediary server for any download requests going to remote repositories / registries. After logging in, these next steps will show you how to configure then test your configuration with local builds for a Maven and npm project.

Maven

If you have an existing Maven configuration file ( settings.xml) that you want to retain, back it up before doing any modifications.

  1. In your file system, open your settings.xml and change the contents of the snippet below. You can find this file in .m2, e.g ~/.m2/settings.xml.

    <settings>
      <mirrors>
    	<mirror>
      	<!--This sends everything else to /public -->
      	<id>nexus</id>
      	<mirrorOf>*</mirrorOf>
      	<url>http://localhost:8081/repository/maven-proxy/</url>
    	</mirror>
      </mirrors>
      <profiles>
    	<profile>
      	<id>nexus</id>
      	<!--Enable snapshots for the built in central repo to direct -->
      	<!--all requests to nexus via the mirror -->
      	<repositories>
        	<repository>
          	<id>central</id>
          	<url>http://central</url>
          	<releases><enabled>true</enabled></releases>
          	<snapshots><enabled>true</enabled></snapshots>
        	</repository>
      	</repositories>
     	<pluginRepositories>
        	<pluginRepository>
          	<id>central</id>
          	<url>http://central</url>
          	<releases><enabled>true</enabled></releases>
          	<snapshots><enabled>true</enabled></snapshots>
        	</pluginRepository>
      	</pluginRepositories>
    	</profile>
      </profiles>
      <activeProfiles>
    	<!--make the profile active all the time -->
    	<activeProfile>nexus</activeProfile>
      </activeProfiles>
    </settings>


  2. Go to the repository manager user interface.

  3. Click the Administration button ui-admin-button-icon.pngin the left navigational menu, then click Repositories.

  4. Click the  Create repository button and choose the maven2 (proxy) recipe from the list.

  5. Add the following text in the required fields:

  6. Click Create repository to complete the form.
  7. From the command-line interface, create  the POM file (pom.xml) with the values below:

    <project>
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.example</groupId>
      <artifactId>nexus-proxy</artifactId>
      <version>1.0-SNAPSHOT</version>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.10</version>
        </dependency>
      </dependencies>
    </project>

     

  8.  Run the Maven build with the command mvn package.


If you to want to view the details of your Maven test build, skip to Part 3. However, if you want to test an npm build, continue to the next section in this part.


npm

If you have an existing npm configuration file (.npmrc) that you want to retain, back it up before doing any modifications.

  1. Click the Administration button ui-admin-button-icon.png in the left navigational menu, then click Repositories.
  2. Click the  Create repository  button  and choose npm (proxy) from the list.

  3. Add the following text in the required fields:

  4. From the command-line interface  r un  npm config set registry http://localhost:8081/repository/npm-proxy

  5. From the command-line interface, create  a package.json with the values below:

    {
      "name": "sample_project1",
      "version": "0.0.1",
      "description": "Test Project 1",
      "dependencies" : {
        "commonjs" : "0.0.1"
      }
    }


  6. Run the npm build with the command  npm install .

Part 3 -  Viewing Proxied Components

After your Maven and npm projects are successfully built, follow these steps to view the cached components:

  1. Click the  Browse  button  , from the main toolbar.

  2. Click Components.

  3. Of your components, choose  maven-proxy  or npm-proxy . You'll see the test component you  proxied for the respective format during the previous build steps.

  4. Click on a component name to review its details.


The Components screen is a sub-section to the Browse interface. So in order to view other components, click Components directly from the current screen and select another repository name from step 3 in this part.