java 如何为Maven设置Archiva内部+快照存储库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7427831/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to setup Archiva internal+snapshot repository for Maven?
提问by NagyI
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. My project has some external dependencies (like log4j
) which are downloaded from the Archiva internal repository correctly. 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 客户端设置为一起使用内部和快照存储库。我的项目有一些外部依赖项(如log4j
),它们是从 Archiva 内部存储库正确下载的。此外,我的项目依赖于自己的项目,该项目的工件已经构建并安装到快照存储库中。但是,如果我尝试构建项目,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.
What did i do wrong? By the way i don't really get the <mirrorOf>
elements purpose. I've tried to replace this at internal mirror settings to central
but this still doesn't fix my problem.
但是,Maven 不会尝试在构建时查找快照存储库。我做错了什么?顺便说一下,我并没有真正理解<mirrorOf>
元素的目的。我试图在内部镜像设置中替换它,central
但这仍然不能解决我的问题。
回答by Raghuram
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.
经过反复试验,以下配置对我有用。在这里,我使用了默认的存档配置 -internal
保存版本并snapshots
仅保存内部快照。
Essentially unlike nexuswe need two separate <mirror>
and <repository>
declarations - one for the normal artifacts and the other for snapshot artifacts.
本质上与nexus不同,我们需要两个单独的<mirror>
and<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>
回答by Simon Hellinger
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.
经过多次反复试验,我得出了一个与 Raghuram 非常相似的配置。然而,使用档案,我发现了一两件可能仍然值得注意的事情。另外,我在我的配置中使用了镜像以供我的项目访问(<distributionManagement/>
在 pom.xml 中设置),而不是直接访问存储库。
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>
部分中提供与在部分中不同的 id <profiles>
,所以我似乎不允许给它们提供与 Raghuram 相同的名称。
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.
现在,设置好 settings.xml 后,我开始更改<distributionManagement>
项目 pom.xml 中的部分。准确地说,我在作为我所有项目的父级的 pom 中更改了此设置:它主要包含该<distributionManagement>
部分,其他很少。这个父 pom 本身被部署到档案。
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).
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)构建项目,而在我的本地构建存储库中没有这些工件中的任何一个(我擦除了我的本地存储库以进行测试)。
下载(
<dependencies>
pom.xml的部分)和上传(<distributionManagement>
pom.xml的部分)现在通过镜像处理。
回答by 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.
通过多次反复试验,我也得到了一个与上面非常相似的配置,但直到我在下面的配置中执行此操作后,事情才对我有用。因此,如果您在组织存储库的帮助下使用 maven 而不是在本地主机中使用,我将发布它以尝试改进答案。
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>