12

最近我们开始与 Artifactory 合作。我们按照 Artifactory 的建议配置了 settings.xml。然而,我们在运行“mvn compile”时下载 jars 时遇到问题,即使它们出现在 Artifactory repo 中。显式添加 repo1-cache 解决了编译问题,但下载是从远程存储库而不是从 Artifactory 执行的。

<repository>
    <id>My Repository</id>
    <name>MyRepository-releases</name>
    <url>http://mvn-srv:8081/artifactory/repo1</url>
</repository>

应该在 settings.xml 中添加什么来自动解决依赖关系并从工件中获取它们而不是每次都访问远程服务器?

设置.xml:

<?xml version="1.0" encoding="UTF-8"?>
<settings
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"
xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<profiles>
    <profile>
        <repositories>
            <repository>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
                <id>central</id>
                <name>libs-release</name>
                <url>http://mvn-srv:8081/artifactory/libs-release</url>
            </repository>
            <repository>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
                <id>snapshots</id>
                <name>libs-snapshot</name>
                <url>http://mvn-srv:8081/artifactory/libs-snapshot</url>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
                <id>central</id>
                <name>plugins-release</name>
                <url>http://mvn-srv:8081/artifactory/plugins-release</url>
            </pluginRepository>
            <pluginRepository>
                <snapshots />
                <id>snapshots</id>
                <name>plugins-snapshot</name>
                <url>http://mvn-srv:8081/artifactory/plugins-snapshot</url>
            </pluginRepository>
        </pluginRepositories>
        <id>artifactory</id>
    </profile>
</profiles>
<activeProfiles>
    <activeProfile>artifactory</activeProfile>
</activeProfiles>
<servers>
    <server>
        <id>MyRepository</id>
    </server>
</servers>

编译错误:

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.355s
[INFO] Finished at: Wed Nov 14 14:52:31 IST 2012
[INFO] Final Memory: 4M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project common: Could not resolve dependencies for project com.myc
ompany.app:common:jar:1.0-SNAPSHOT: The following artifacts could not be resolved: commons-jxpath:co
mmons-jxpath:jar:1.3-osgi, xpp3:xpp3_min:jar:1.1.3.4.O-osgi, net.java.dev.stax-utils:stax-utils:jar:
20080702-osgi, net.sf.saxon:saxon:jar:8.9.0.4-osgi, net.sf.saxon:saxon-dom:jar:8.9.0.4-osgi, net.sf.
saxon:saxon-xqj:jar:8.9.0.4, dom4j:dom4j:jar:1.6.1-osgi, mx4j:mx4j-jmx:jar:2.1.1-osgi, mx4j:mx4j-imp
l:jar:2.1.1-osgi, mx4j:mx4j-tools:jar:2.1.1-osgi, mx4j:mx4j-remote:jar:2.1.1-osgi, com.yourkit:yjp-c
ontroller-api-redist:jar:9.0.8, org.apache.geronimo.specs:geronimo-jms_1.1_spec:jar:1.1-osgi, common
s-codec:commons-codec:jar:1.3-osgi, commons-httpclient:commons-httpclient:jar:3.1-osgi, quartz:quart
z-all:jar:1.6.6: Could not find artifact commons-jxpath:commons-jxpath:jar:1.3-osgi in central (http
://mvn-srv:8081/artifactory/libs-release) -> [Help 1]
4

2 回答 2

8

添加到@duncan-jones 出色的答案,解决问题的好方法是执行Trace Artifact Retrieval调用,在您的情况下:

http://mvn-srv:8081/artifactory/libs-release/commons-jxpath/commons-jxpath/1.3-osgi/commons-jxpath-1.3-osgi.jar?trace

顺便说一句,我什至在repo1中都没有看到 1.3-osgi 版本。

于 2012-11-14T14:52:04.643 回答
7

您需要确保您的虚拟存储库映射到您期望的真实存储库。

例如,libs-release通常会映射到内部和外部版本存储库。也许这是错误的配置,导致它无法访问您想要的存储库。

在 Artifactory 中,转到 Admin 页面并查看Configuration > Repositories。在页面底部,查看您的虚拟存储库。双击它们将显示包含的内容。

对我来说,libs-release包括和。后者是另一个虚拟存储库,它映射到我安装中列出的所有外部存储库,例如 codehaus、repo1、jboss、google-code...libs-release-localext-release-localremote-repos

也许缺少这些虚拟存储库之一repo1

于 2012-11-14T14:09:59.893 回答