简体   繁体   English

具有已知未知主机的多个Maven存储库

[英]Multiple maven repositories with a known unknown host

Description 描述

I'm configurating a maven build, to execute in two different environments, the first one in my localhost, and the second one inside a docker cluster using jenkins. 我正在配置一个Maven构建,以在两个不同的环境中执行,第一个在我的本地主机中,第二个在使用jenkins的docker集群中执行。

Both builds will use the same pom.xml file. 两个构建都将使用相同的pom.xml文件。 Inside the pom.xml file I'm referencing a private nexus repository. 在pom.xml文件中,我引用了一个私有的关系存储库。

The nexus repository is inside the docker cluster. nexus存储库位于docker集群内部。

Both the URL's defined inside pom.xml redirect to the same nexus repository. pom.xml中定义的两个URL都重定向到相同的关系存储库。

So to access the nexus repository from my localhost, we've configured our private DNS to resolve "git.consignet.intranet" to the nexus repo. 因此,要从我的本地主机访问nexus存储库,我们已经配置了私有DNS来将“ git.consignet.intranet”解析为nexus存储库。 And then to access the nexus repo inside docker, I can use just its service name "nexus-repo". 然后在docker内部访问nexus repo,我可以仅使用其服务名称“ nexus-repo”。

The pom.xml's relevant contents are shown below: pom.xml的相关内容如下所示:

<project>
    ...
    <repositories>
        <repository>
            <id>nexus-aws</id>
            <name>Nexus Amazon</name>
            <url>http://nexus.consignet.intranet/repository/maven-releases/</url>
        </repository>
        <repository>
            <id>nexus-cluster</id>
            <name>Nexus Inside Cluster</name>
            <url>http://nexus-repo/repository/maven-releases/</url>
        </repository>
    </repositories>
    ...
</project>

Problem 问题

While building in my localhost I'm not able to access the repo using its service name inside docker to resolve to the host. 在我的本地主机中构建时,我无法使用泊坞窗中的服务名称来访问存储库以解析到主机。

While building inside jenkins (Inside the docker container), I'm not able to access our DNS server to resolve the URL. 在jenkins内部(在docker容器内部)构建时,我无法访问我们的DNS服务器来解析URL。

Maven output Maven输出

Maven throws the following error message: Maven引发以下错误消息:

[ERROR] Failed to execute goal on project DB1ConsignetWebService: Could not 
resolve dependencies for project DB1ConsignetWebService:DB1ConsignetWebService:war:1.0-SNAPSHOT: 
Failed to collect dependencies at Consignet:jaxb-api:jar:2.2.7-facets-1.0.5:
Failed to read artifact descriptor for Consignet:jaxb-api:jar:2.2.7-facets-1.0.5: 
Could not transfer artifact Consignet:jaxb-api:pom:2.2.7-facets-1.0.5
from/to my-repo1 (http://nexus-repo/repository/maven-releases/): nexus-repo: 
Unknown host nexus-repo -> [Help 1]

Final considerations 最后考虑

Only one URL can be resolved in each environment: 在每个环境中只能解析一个URL:

Inside development environment, I'll just be able to resolve the "git.consignet.intranet" dns. 在开发环境中,我将只能解析“ git.consignet.intranet” dns。

Inside jenkins build environment, I'll just be able to resolve the "nexus-repo" dns. 在jenkins构建环境中,我将只能解析“ nexus-repo” dns。

Question

Is it possible to ignore a repository in maven if it is a unknown host? 如果它是未知主机,是否可以忽略Maven中的存储库? If so, how can I configure it? 如果可以,该如何配置?

Use profiles: 使用配置文件:

<profiles>
    <profile>
         <id>dev</id>
         <repositories>
            <repository>
                <id>nexus-aws</id>
                <name>Nexus Amazon</name>
                <url>http://nexus.consignet.intranet/repository/maven-releases/</url>
            </repository>
        </repositories>
    </profile>

    <profile>
        <id>jenkins</id>
        <repositories>
            <repository>
                <id>nexus-cluster</id>
                <name>Nexus Inside Cluster</name>
                <url>http://nexus-repo/repository/maven-releases/</url>
            </repository>
        </repositories>
    <profile>
</profiles>

Then build with mvn -Pjenkins or mvn -Pdev , depending on which environment you are in. The problem is now (hopefully) reduced to reading environment flags. 然后使用mvn -Pjenkinsmvn -Pdev ,具体取决于您所处的环境。现在(希望如此)该问题已减少为读取环境标志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM