我有一个私有(private) Nexus,其存储库通过身份验证保护。
拉取库就像一个魅力,但如果我想使用其中存储的原型(prototype)之一,我总是需要在原型(prototype)目录的 URL 中写入纯文本用户名和密码,如下所示:
mvn archetype:generate -DarchetypeCatalog=http://username:password@maven.mycompany.com/nexus/content/repositories/myrepo/archetype-catalog.xml
我读了http://maven.apache.org/archetype/maven-archetype-plugin/faq.html#authentication并用我从那一点点帮助中理解的内容更新了我的 settings.xml:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>myrepo</id>
<username>username</username>
<password>{HASHED_PASSWORD}</password>
</server>
<server>
<id>pretty-archetype-unicorn-repo</id>
<username>username</username>
<password>{HASHED_PASSWORD}</password>
</server>
</servers>
<profiles>
<profile>
<id>someid</id>
<repositories>
<repository>
<id>myrepo</id>
<name>My Repo</name>
<url>http://maven.mycompany.com/nexus/content/repositories/myrepo/</url>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>someid</activeProfile>
</activeProfiles>
</settings>
不用说,它不起作用,当我尝试时:
mvn archetype:generate -DarchetypeCatalog=http://maven.mycompany.com/nexus/content/repositories/myrepo/archetype-catalog.xml
我得到同样的旧:
[WARNING] Error reading archetype catalog http://maven.mycompany.com/nexus/content/repositories/myrepo/archetype-catalog.xml
org.apache.maven.wagon.authorization.AuthorizationException: Access denied to: http://maven.mycompany.com/nexus/content/repositories/myrepo/archetype-catalog.xml
任何提示,或带有工作示例的更好文档?
最佳答案
如果您至少不指定 -DarchetypeArtifactId
,则目前无法做到这一点。 .根据您链接的官方文档:
The server id used to download the artifact is [archetypeArtifactId]-repo
因此,如果目录受密码保护(并且您不愿意在 shell 历史记录中公开用户名/密码),则无法仅浏览目录。
同时,您可以继续投票给ARCHETYPE-204 .多年来他们已经有一个补丁可用,他们可能只需要一点插入。
更新
调查 source code maven 原型(prototype)项目,看起来像
settings.xml
中的以下片段可能对你有用:<servers>
<server>
<id>archetype</id>
<username>${your username}</username>
<password>${your password}</password>
</server>
</servers>
有一个默认 ID
archetype
在构建 Repository
时获取远程目录时的对象。我不认为这是处理这种情况的官方方式,而且它有点脏 IMO。但它可能仍然对你有用:-)此外,您应该能够设置配置文件以重用
archetype
不同服务器的 ID。
关于maven - 如何在 URL 中没有用户名和密码的情况下从我自己经过身份验证的关系中获取 Maven 原型(prototype)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14811535/