How to setup Archiva internal+snapshot repository for Maven?

落花浮王杯 提交于 2019-12-02 19:18:59

The following configuration worked for me after some trial and error. Here I used the default archiva configuration - internal to hold releases and snapshots to hold only the internal snapshots.

Essentially unlike nexus we need two separate <mirror> and <repository> declarations - one for the normal artifacts and the other for snapshot artifacts.

<mirrors>
    <mirror>
        <id>archiva</id>
        <mirrorOf>*</mirrorOf>
        <url>http://localhost:8080/archiva/repository/internal</url>
    </mirror>
    <mirror>
        <id>snapshots</id>
        <mirrorOf>snapshots</mirrorOf>
        <url>http://localhost:8080/archiva/repository/snapshots</url>
    </mirror>
</mirrors>
<profiles>
    <profile>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <repositories>
            <repository>
              <id>internal</id>
              <name>Archiva Managed Internal Repository</name>
              <url>http://localhost:8080/archiva/repository/internal/</url>
              <releases>
                <enabled>true</enabled>
              </releases>
              <snapshots>
                <enabled>false</enabled>
              </snapshots>
            </repository>
            <repository>
              <id>snapshots</id>
              <name>Archiva Managed Internal Repository</name>
              <url>http://localhost:8080/archiva/repository/snapshots/</url>
              <releases>
                <enabled>false</enabled>
              </releases>
              <snapshots>
                <enabled>true</enabled>
              </snapshots>
            </repository>
        </repositories>
    </profile>
</profiles>

Through much trial and error I came to a configuration quite similar to Raghuram's. Yet, using archiva, I found one or two things that might still be noteworthy. Also, I used the mirrors in my configuration to be accessed by my projects (set in <distributionManagement/> in the pom.xml), instead of directly accessing the repositories.

This is the relevant part of my maven settings.xml:

<!-- set up servers to point to mirror, for use in project pom -->
<servers>
  <server>
    <id>my.snapshots</id> <!-- use name of the mirror here -->
    <username>user</username>
    <password>pwd</password>
  </server>
</servers>

<!-- map mirror names to actual repositories -->
<mirrors>
  <!-- leave the default mirror in place -->
  <mirror>
    <id>archiva.default</id>
    <mirrorOf>*</mirrorOf>
    <url>http://server:port/archiva/repository/internal/</url>
  </mirror>
  <!-- enter my own -->
  <mirror>
    <id>my.snapshots</id>
    <mirrorOf>archiva.snapshots</mirrorOf>
    <url>http://server:port/archiva/repository/snapshots/</url>
  </mirror>
<mirrors>

<!-- activate the repo for artifact downloads by setting profile -->
<profiles>
  <activation>
    <activeByDefault>true</activeByDefault>
  </activation>
  <repositories>
    <repository> <!-- mirror will be used during runtime instead of this -->
      <id>archiva.snapshots</id> <!-- do not use mirror name here -->
      <url>http://server:port/archiva/repository/snapshots/</url>
      <releases>
        <enabled>false</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
  </repositories>
</profile>

I found out that I had to give different ids in the <mirrors> section than in the <profiles> section, so I seemingly wasn't allowed to give them the same name as Raghuram did.

Now, with the settings.xml in place, I set out to change the <distributionManagement> section in my project's pom.xml. To be precise, I changed this setting in a pom that is parent to all my projects: It chiefly contains the <distributionManagement> section and little else. This parent pom is itself deployed to archiva.

This is the relevant section of the parent pom.xml:

<distributionManagement>
  <repository>
    ...
  </repository>
  <snapshotRepository>
    <id>my.snapshots</id>
    <name>Archiva Managed Snapshot Repository</name>
    <url>http://server:port/archiva/repository/snapshots</url>
    <layout>default</layout>
  </snapshotRepository>
</distributionManagement>

This kind of streamlined things, and it has, I think, some benefits:

  • I am now able to build projects depending on my own artifacts (including parent pom), without having either of those artifacts in my local build repository (I wiped my local repository for testing this).

  • Downloads (the <dependencies> sections of the pom.xml) as well as uploads (the <distributionManagement> sections of the pom.xml) are now handled via the mirrors.

kagopiee

Through much trial and error I too came to a configuration quite similar above one but things didnt workout for me until I did this below configuration. Hence am posting it in an attempt to improve answer if you are using maven with the help of your organisation repository instead of using in your localhost.

This answer is for those who need multiple mirror configurations for multiple repositories maintained b your organisation, then this would serve as an example.

my.snapshots user pwd

<!-- map mirror names to actual repositories -->
<mirrors>
   <!-- enter my own -->
  <mirror>
    <id>my.snapshots</id>
    <mirrorOf>archiva.snapshots</mirrorOf> <!-- this name should be the same as configured for the below repository id.>
    <url>http://server:port/archiva/repository/snapshots/</url>
  </mirror>
  <!-- leave the default mirror in place -->
  <mirror>
    <id>archiva.default</id>
    <mirrorOf>central</mirrorOf> < !-- Instead of *, replace it with "central"-->
    <url>http://server:port/archiva/repository/internal/</url>
  </mirror>
<mirrors>

<!-- activate the repo for artifact downloads by setting profile -->
<profiles>
  <activation>
    <activeByDefault>true</activeByDefault>
  </activation>
  <repositories>
    <repository> <!-- mirror will be used during runtime instead of this -->
      <id>archiva.snapshots</id> <!-- do not use mirror name here -->
      <url>http://server:port/archiva/repository/snapshots/</url>
      <releases>
        <enabled>false</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
  </repositories>
</profile>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!