Sunday 6 October 2019

Nexus: Maven Repository Group


What is Repository Group?
A repository group is a collection of other repositories. You can combine multiple repositories of same format to a single repository group.

Why Repository Group is required?
Using Repository Group, developer can use the group url to access the artefacts.

For example, you can create a repository group with Maven central Proxy repository, internal hosted repository for 3rd party artefacts into a group. So developers can use the group url to download both artefacts available in proxy, hosted repositories.



Nexus default repository groups
Nexus repository manager comes with below groups by default.

a.   maven-public: This group combines maven2 formatted repositories. This group combines the external proxy for the Central Repository, and thee hosted repositories maven-releases and maven-snapshots.

b.   nuget-group: This group combines NuGet formatted repositories. This group combines nuget-hosted and nuget.org-proxy repositories.

Can a repository group store artefacts?
No, it will not store any artefacts. It combines other repository groups. When a request for an artefact come to repository group, it scans all the repositories that are part of this group one by one, whenever it finds a first match it return the artefact.

Create Group Repository
Login to nexus repository manager.

Click on  ‘Server administration and configuration’ icon.


Click on Repositories link.


Click on ‘Create repository’ button.

Select maven2 (group) recipe.


Give group name as ‘testMavenGroup’, Select the repositories that you want them to be part of the group. Click on ‘Create repository’ button.

You will be redirected to repositories listing page.

You can see testMavenGroup repository is created. You can copy the url of this group by clicking on ‘copy’ link (http://localhost:8081/repository/testMavenGroup/).

settings.xml
<settings>
  <mirrors>
    <mirror>
      <!--This sends everything else to /public -->
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://localhost:8081/repository/testMavenGroup/</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>
 <servers>
    <server>
      <id>nexus</id>
      <username>admin</username>
      <password>password123</password>
    </server>
  </servers>
</settings>


pom.xml
<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.sample.app</groupId>
    <artifactId>nexus-proxy-test</artifactId>
    <version>1.0</version>
    
    <dependencies>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.5</version>
        </dependency>
    </dependencies>
    
    <distributionManagement>
        <repository>
            <id>nexus</id>
            <name>maven-releases</name>
            <url>http://localhost:8081/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>nexus</id>
            <name>maven-snapshots</name>
            <url>http://localhost:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>
</project>



Go to the location where pom.xml is located and execute the command mvn install, you can see that the build successful message.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.641 s
[INFO] Finished at: 2019-10-04T18:38:25+05:30
[INFO] ------------------------------------------------------------------------



Previous                                                    Next                                                    Home

No comments:

Post a Comment