如何为mvn构建设置多个存储库?

时间:2018-05-03 20:58:27

标签: maven mvn-repo

我想从中央maven存储库下载像Spring框架这样的'标准'jars,但是我们从我们的自定义maven存储库(Artifactory)repo下载专有的许可证罐。我用这种方式设置了pom.xml文件:

    <repositories>
    <repository>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <id>central</id>
        <name>maven2</name>
        <url>https://repo.maven.apache.org/maven2</url>
    </repository>   
    <repository>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <id>2</id>
        <name>Artifactory</name>
        <url>https://na.artifactory.swg-devops.com/artifactory/gbs-ic2esprint-bluecost-libs-maven-virtual</url>
    </repository>
</repositories>  

它不按我想要的方式工作。这是我现在得到的:

    [INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building SpreadSheetUploadWeb 1.0
[INFO] ------------------------------------------------------------------------
[INFO] Downloading: https://repo.maven.apache.org/maven2/com/fasterxml/jackson/core/jackson-databind/1.9.10/jackson-databind-1.9.10.pom
[INFO] Downloading: https://na.artifactory.swg-devops.com/artifactory/gbs-ic2esprint-bluecost-libs-maven-virtual/com/fasterxml/jackson/core/jackson-databind/1.9.10/jackson-databind-1.9.10.pom
[INFO] Downloading: http://repo.spring.io/ext-release-local/com/fasterxml/jackson/core/jackson-databind/1.9.10/jackson-databind-1.9.10.pom
[INFO] Downloading: http://repo.spring.io/milestone/com/fasterxml/jackson/core/jackson-databind/1.9.10/jackson-databind-1.9.10.pom
[INFO] Downloading: http://repo.spring.io/snapshot/com/fasterxml/jackson/core/jackson-databind/1.9.10/jackson-databind-1.9.10.pom
[INFO] Downloading: https://repo.maven.apache.org/maven2/com/fasterxml/jackson/core/jackson-annotations/1.9.10/jackson-annotations-1.9.10.pom
[INFO] Downloading: https://na.artifactory.swg-devops.com/artifactory/gbs-ic2esprint-bluecost-libs-maven-virtual/com/fasterxml/jackson/core/jackson-annotations/1.9.10/jackson-annotations-1.9.10.pom
[INFO] Downloading: https://repo.maven.apache.org/maven2/com/fasterxml/jackson/core/jackson-core/1.9.10/jackson-core-1.9.10.pom
[INFO] Downloading: https://na.artifactory.swg-devops.com/artifactory/gbs-ic2esprint-bluecost-libs-maven-virtual/com/fasterxml/jackson/core/jackson-core/1.9.10/jackson-core-1.9.10.pom
[INFO] Downloading: https://repo.maven.apache.org/maven2/com/ibm/db2/jcc/db2jcc_license_cisuz/10.5.9/db2jcc_license_cisuz-10.5.9.pom
[INFO] Downloading: https://na.artifactory.swg-devops.com/artifactory/gbs-ic2esprint-bluecost-libs-maven-virtual/com/ibm/db2/jcc/db2jcc_license_cisuz/10.5.9/db2jcc_license_cisuz-10.5.9.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.403 s
[INFO] Finished at: 2018-05-04T07:47:47-06:00
[INFO] Final Memory: 17M/153M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project SpreadSheetUploadWeb: Could not resolve dependencies for project SpreadSheetUploadWeb:SpreadSheetUploadWeb:jar:1.0: Failed to collect dependencies at org.springframework.boot:spring-boot-starter-thymeleaf:jar:1.4.3.RELEASE -> org.springframework.boot:spring-boot-starter-web:jar:1.4.3.RELEASE -> com.fasterxml.jackson.core:jackson-databind:jar:1.9.10: Failed to read artifact descriptor for com.fasterxml.jackson.core:jackson-databind:jar:1.9.10: Could not transfer artifact com.fasterxml.jackson.core:jackson-databind:pom:1.9.10 from/to 2 (https://na.artifactory.swg-devops.com/artifactory/gbs-ic2esprint-bluecost-libs-maven-virtual): Access denied to https://na.artifactory.swg-devops.com/artifactory/gbs-ic2esprint-bluecost-libs-maven-virtual/com/fasterxml/jackson/core/jackson-databind/1.9.10/jackson-databind-1.9.10.pom. Error code 401, Unauthorized -> [Help 1]
[ERROR]

1 个答案:

答案 0 :(得分:1)

标记不会影响maven使用存储库获取依赖关系的顺序。

所以maven中心应该是核心,只是为了良好的实践。

但是,您的订单是正确的,但您的链接不正确。您没有正确指定中央存储库。试试这个:

<repository>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <id>central</id>
            <name>maven2</name>
            <url>https://repo.maven.apache.org/maven2</url>
</repository>  

对于您的神器,如果您可以连接到https://swg-devops.com/artifactory,请尝试使用浏览器。也可以尝试https://repo.maven.apache.org/maven2,你应该看看它应该是什么样子。当您解析了正确的链接后,您应该能够下载依赖项,并且maven会自动从头到尾尝试所有存储库以查找依赖项。