![](/img/trans.png)
[英]artifactory-maven-plugin: How to resolve dependencies from private Artifactory without settings.xml
[英]How to configure settings.xml to pull from Artifactory private virtual repository?
我是Apache Archiva的資深人士,他最近轉投Artifactory Pro。 我一直試圖在Artifactory中復制一個我在Archiva中實現虛擬私有存儲庫的設置。 最終結果應該是不同的團隊可以訪問他們自己團隊的工件,遠程存儲庫,默認本地存儲庫和公司范圍的存儲庫。
但是,每當我配置我的Maven settings.xml以使用我的私有虛擬存儲庫時,我只能下載一些依賴項,這些依賴項可以從Maven Central獲取和從中提取。 如果我使用Artifactory的默認settings.xml(libs-release,libs-snapshot,plugins-release,plugins-snapshot和no virtual repository),那么我可以下載Maven Central上可用的所有依賴項以及我的項目所需的依賴項。
我在Windows服務器2012虛擬服務器上運行他們提供的Tomcat上的Artifactory v4.4.2。 我沒有在代理后面跑。 我對Archiva沒有這樣的問題。
關於我的私有虛擬存儲庫設置,我有一個名為“test”的虛擬存儲庫,它是一個“通用”軟件包類型。 該存儲庫包含以下存儲庫:
列出的前5個repos是提供Artifactory的默認虛擬存儲庫repos。 列出的最后4個回購是本地回購,它們是通用包類型。
我想我應該用鏡子。
這是我正在使用的一個示例settings.xml(我的用戶名和密碼將填充在我保存到Maven conf文件夾的生成的settings.xml中):
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<servers>
<server>
<username>${security.getCurrentUsername()}</username>
<password>${security.getEscapedEncryptedPassword()!"*** Insert encrypted password here ***"}</password>
<id>central</id>
</server>
<server>
<username>${security.getCurrentUsername()}</username>
<password>${security.getEscapedEncryptedPassword()!"*** Insert encrypted password here ***"}</password>
<id>snapshots</id>
</server>
</servers>
<mirrors>
<mirror>
<mirrorOf>*</mirrorOf>
<name>test</name>
<url>http://localhost:8082/artifactory/test</url>
<id>test</id>
</mirror>
</mirrors>
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>libs-release</name>
<url>http://localhost:8082/artifactory/libs-release</url>
</repository>
<repository>
<snapshots />
<id>snapshots</id>
<name>libs-snapshot</name>
<url>http://localhost:8082/artifactory/libs-snapshot</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>plugins-release</name>
<url>http://localhost:8082/artifactory/plugins-release</url>
</pluginRepository>
<pluginRepository>
<snapshots />
<id>snapshots</id>
<name>plugins-snapshot</name>
<url>http://localhost:8082/artifactory/plugins-snapshot</url>
</pluginRepository>
</pluginRepositories>
<id>artifactory</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>
我無法從Maven Central通過我的虛擬存儲庫提取的工件示例是poi-ooxml-schemas-3.10-FINAL.jar或許多Apache Maven插件。 一旦刪除鏡像部分,我就可以從Maven Central下載所有依賴項。 這對我來說毫無意義。 我的虛擬存儲庫配置為包含remote-repos虛擬存儲庫,因此應該能夠從Maven Central中提取所有內容。
我究竟做錯了什么?
好吧我通過JFrog支持人員的幫助自己找出了答案的一部分和答案的另一部分。
這是我發現的第一組問題:
這些問題對我來說似乎是個錯誤。
因此,我最終定義了一個虛擬存儲庫(在下面的配置中命名為test-maven)和兩個本地存儲庫,所有這些都是Maven類型。 這兩個本地存儲庫包含在虛擬存儲庫中。
我想出了一個有效的settings.xml,但它使用了一個鏡像,JFrog支持人員告訴我這不是最佳做法。 記住這個建議,這是最適合我的settings.xml:
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<servers>
<server>
<username>USERNAME</username>
<password>PASSWORD</password>
<id>test-maven</id>
</server>
</servers>
<profiles>
<profile>
<repositories>
<repository>
<snapshots />
<id>test-maven</id>
<name>test-maven</name>
<url>http://localhost:8082/artifactory/test-maven</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots />
<id>test-maven</id>
<name>test-maven</name>
<url>http://localhost:8082/artifactory/test-maven</url>
</pluginRepository>
</pluginRepositories>
<id>artifactory</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>
使用此配置,我驗證了我可以下載發布到Maven Central的所有工件,更多遠程存儲庫,本地快照Maven存儲庫中的快照以及本地快照Maven存儲庫中的發行版。 此設置允許我為每個開發團隊使用私有存儲庫。
一旦刪除鏡像部分,我就可以從Maven Central下載所有依賴項。
您無法訪問鏡像,因為您尚未指定要使用的憑據。 (您也沒有啟用匿名訪問)
來自: https : //www.jfrog.com/confluence/display/RTF/Maven+Repository#MavenRepository-ConfiguringAuthentication
文件中指定的每個<repository>和<mirror>元素必須具有相應的<server>元素,其中<id>指定用戶名和密碼。
你的鏡子的id是測試。 所以你需要為它添加另一個服務器條目:
<servers>
<server>
<username>USERNAME</username>
<password>PASSWORD</password>
<id>test-maven</id>
</server>
<server>
<!-- credentials for mirror -->
<username>USERNAME</username>
<password>PASSWORD</password>
<id>test</id>
</server>
</servers>
Artifactory的“設置我”功能來創建settings.xml文件並不會自動為鏡像添加<server>條目,這有點令人討厭。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.