Inclusive and exclusive routing

When Maven asks for an artifact from a Nexus proxy repository, Nexus knows where to look for it. For example, we have a proxy repository that runs at http://localhost:8081/nexus/content/repositories/central/, which internally points to the remote repository that runs at https://repo1.maven.org/maven2/. Since there is one-to-one mapping between the proxy repository and the corresponding remote repository, Nexus can route the requests without much trouble. However, if Maven looks for an artifact via a Nexus group repository, then Nexus has to iterate through all the repositories in that group repository in order to find the exact artifact. There can be cases where we have more than 20 repositories in a single group repository, which can easily bring delays at the client side. To optimize artifact discovery in group repositories, we need to set the correct inclusive/exclusive routing rules.

Inclusive routing rules talk about which repositories to be included in artifact discovery, while exclusive routing rules talk about which ones to be excluded. The following steps show how to include and exclude routes:

  1. Go to http://localhost:8081/nexus and log in as admin.
  2. Navigate to Views/Repositories | Routing | Add. Fill in the required details appropriately, as shown in the following screenshot:
    Inclusive and exclusive routing
  3. The URL Pattern field carries a regular expression to the artifact path. The artifact path is everything that comes after nexus/content that also includes the repository name. In this case, we use ^/org/apache/axis2/.* as the regular expression to create an inclusive route to the central proxy repository.
  4. Any request coming to the packt-group group repository, which matches the given regular expression, will now be directly routed to the central proxy repository at http://localhost:8081/nexus/content/groups/packt-group/org/apache/axis2/axis2-kernel/1.6.2/axis2-kernel-1.6.2.jar.
  5. In the same way, we can also create an exclusive route. Here, you need to select a set of repositories from the provided list to be excluded from artifact discovery corresponding to the matching regular expression.

    If you have blocked a certain artifact from a repository and you later unblock it or set a different route type for it, you might see the following exception from your Maven project, when you try to execute mvn clean install. As clearly indicated in the exception, the issue is related to caching. If an artifact gets blocked from a given repository, that decision will be cached until the update interval of the repository gets elapsed. In that case, you need to execute mvn clean install –U.

    [ERROR] Failed to execute goal on project com.packt.samples.archetype: Could not resolve dependencies for project com.packt.samples:com.packt.samples.archetype:jar:1.0.0: Failure to find org.apache.axis2:axis2-kernel:jar:1.6.2 in http://localhost:8081/nexus/content/groups/packt-group/ was cached in the local repository, resolution will not be reattempted until the update interval of packt-group has elapsed or updates are forced.
    
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.138.202