简体   繁体   English

如何为Maven设置Archiva内部+快照存储库?

[英]How to setup Archiva internal+snapshot repository for Maven?

We are trying to use Archiva as a Maven proxy for central and other external repositories and also as a snapshot storage for our artifacts which are automatically built by Hudson from SVN and installed to the snapshot repository. 我们正在尝试将Archiva用作中央和其他外部存储库的Maven代理,并将其作为我们的工件的快照存储,这些工件由Hudson从SVN自动构建并安装到快照存储库。

I can't setup my Maven client to use the internal and snapshots repositories together. 我无法将我的Maven客户端设置为一起使用内部和快照存储库。 My project has some external dependencies (like log4j ) which are downloaded from the Archiva internal repository correctly. 我的项目有一些外部依赖项(如log4j ),它们可以正确地从Archiva内部存储库下载。 Also my project has a dependency to an own project which's artifact is already built and installed to the snapshot repository. 此外,我的项目依赖于一个自己的项目,该项目的工件已经构建并安装到快照存储库中。 However if i try to build the project Maven can't find my snapshot artifact. 但是,如果我尝试构建项目,Maven无法找到我的快照工件。

My configuration file had originally this setting: 我的配置文件原来是这个设置:

<mirror>
  <id>company-internal</id>
  <name>Company's Archiva - Internal Repository</name>
  <url>http://www.mycompany.hu/archiva/repository/internal</url>
  <mirrorOf>*</mirrorOf>
</mirror>

and then i added the following: 然后我添加了以下内容:

<mirror>
 <id>company-snapshots</id>
 <name>Company Archiva - Snapshots Repository</name>
 <url>http://www.mycompany.hu/archiva/repository/snapshots</url>
 <mirrorOf>apache.snapshots</mirrorOf>
</mirror>

However Maven doesn't tries to look up the snaphot repository at build. 但是,Maven不会尝试在构建时查找snaphot存储库。 What did i do wrong? 我做错了什么? By the way i don't really get the <mirrorOf> elements purpose. 顺便说一句,我并没有真正得到<mirrorOf>元素的目的。 I've tried to replace this at internal mirror settings to central but this still doesn't fix my problem. 我试图将内部镜像设置替换为central但这仍然无法解决我的问题。

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. 在这里,我使用默认的archiva配置 - internal用于保存版本和snapshots以仅保留内部快照。

Essentially unlike nexus we need two separate <mirror> and <repository> declarations - one for the normal artifacts and the other for snapshot artifacts. 基本上与nexus不同,我们需要两个单独的<mirror><repository>声明 - 一个用于普通工件,另一个用于快照工件。

<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. 通过大量的反复试验,我得出了一个与Raghuram非常相似的配置。 Yet, using archiva, I found one or two things that might still be noteworthy. 然而,使用archiva,我发现了一两件可能仍然值得注意的事情。 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. 另外,我使用我的配置中的镜像来访问我的项目(在pom.xml中的<distributionManagement/>中设置),而不是直接访问存储库。

This is the relevant part of my maven settings.xml: 这是我的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. 我发现我必须在<mirrors>部分给出不同于<profiles>部分的id,所以我似乎不允许给他们与Raghuram一样的名字。

Now, with the settings.xml in place, I set out to change the <distributionManagement> section in my project's pom.xml. 现在,使用settings.xml,我开始更改项目的pom.xml中的<distributionManagement>部分。 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. 确切地说,我在一个pom中更改了此设置,该pom是我所有项目的父级:它主要包含<distributionManagement>部分,而其他内容则很少。 This parent pom is itself deployed to archiva. 这个父pom本身已部署到archiva。

This is the relevant section of the parent pom.xml: 这是父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). 我现在能够根据我自己的工件(包括父pom)构建项目,而我的本地构建存储库中没有这些工件(我擦除了我的本地存储库以进行测试)。

  • 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. 下载(pom.xml的<dependencies>部分)以及上传(pom.xml的<distributionManagement>部分)现在通过镜像处理。

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. 因此,如果您在组织存储库的帮助下使用maven而不是在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 my.snapshots用户密码

<!-- 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM