V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
leiuu
V2EX  ›  程序员

maven 新手求救,如何正确利用 maven 私服 nexus 中的多个 repo?

  •  
  •   leiuu · 2019-11-08 13:12:53 +08:00 · 1306 次点击
    这是一个创建于 1624 天前的主题,其中的信息可能已经有所发展或是发生改变。

    有一个困惑 ,Nexus Repository Manager 配置了多个 repo ( repository ) ,每一个对应了不同的路径。

    项目构建中的 jar 包可能依赖其中多个 repo,该如何配置 settings.xml ,使得项目构建过程中会自动搜索 nexus 上的所有 repo。

    Nexus 界面截图: nexus

    可以看到其中有多个 repo,每个 repo 的 repo path 不一致。

    例如,现在做了如下配置:

     <profiles>
            <profile>
                <id>nexus</id>
                <repositories>
                    <repository>
                        <id>nexus</id>
                        <url>http://10.11.110.42:8081/nexus/content/groups/public/</url>
                        <snapshots>
                            <enabled>true</enabled>
                        </snapshots>
                        <releases>
                            <enabled>true</enabled>
                        </releases>
                    </repository>
                </repositories>
            </profile>
        </profiles>
        <activeProfiles>
            <activeProfile>nexus</activeProfile>
        </activeProfiles>
    
    
    

    项目构建时只能从这个 /nexus/content/groups/public/ 路径下搜索 jar,而部分需要的 jar 包在 nexus 的其他路径下,这时该怎么处理。

    第 1 条附言  ·  2019-11-08 16:20:06 +08:00
    使用管理员账户登录后,点击 public repo 发现,全部的 repo 已经在 public group 中了( order group repo )。
    ![a.png]( https://i.loli.net/2019/11/08/4vmNiV5u7SBn1XI.jpg)
    关于 public repo 的管理,这里有一篇[介绍]( https://help.sonatype.com/repomanager2/configuration/managing-repository-groups)。
    之后更改了一下 maven settings.xml ,目前看似乎没有问题,终于可以正常构建了!
    第 2 条附言  ·  2019-11-08 16:20:53 +08:00

    maven 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>nexus</id>
                <username>username</username>
                <password>password</password>
            </server>
        </servers>
        <mirrors>
            <mirror>
                <id>nexus</id>
                <name>nexus</name>
                <url>http://10.11.110.42:8081/nexus/content/groups/public</url>
                <mirrorOf>*</mirrorOf>
            </mirror>
        </mirrors>
        <profiles>
            <profile>
                <id>nexus</id>
                <repositories>
                    <repository>
                        <id>nexus</id>
                        <url>http://10.11.110.42:8081/nexus/content/groups/public/</url>
                        <snapshots>
                            <enabled>true</enabled>
                        </snapshots>
                        <releases>
                            <enabled>true</enabled>
                        </releases>
                    </repository>
                </repositories>
                <pluginRepositories>
                    <pluginRepository>
                        <id>nexus</id>
                        <url>http://10.11.110.42:8081/nexus/content/groups/public/</url>
                        <snapshots>
                            <enabled>true</enabled>
                        </snapshots>
                        <releases>
                            <enabled>true</enabled>
                        </releases>
                    </pluginRepository>
                </pluginRepositories>
            </profile>
        </profiles>
        <activeProfiles>
            <activeProfile>nexus</activeProfile>
        </activeProfiles>
    </settings>
    
    6 条回复    2019-11-08 17:13:36 +08:00
    Aruforce
        1
    Aruforce  
       2019-11-08 13:18:56 +08:00
    在 nexus 上把所有的 repo 都加到 public 那个 group 里;

    然后在 setting.xml 里面使用 public group 做 Mirror, mirrorof *

    然后 OK....
    lc7029
        2
    lc7029  
       2019-11-08 13:43:51 +08:00
    你把所有的 repo 加入到一个组,然后引用这个组就好了
    leiuu
        3
    leiuu  
    OP
       2019-11-08 13:49:44 +08:00 via Android
    @Aruforce
    @lc7029
    感谢,这样发布代码的时候会有问题吗
    不同 type 的 repo,如: group hosted proxy 也可以加到一组中吗
    yinzhili
        4
    yinzhili  
       2019-11-08 14:47:58 +08:00
    分组就可以了
    leiuu
        5
    leiuu  
    OP
       2019-11-08 16:03:00 +08:00
    @yinzhili 发现全部的 repo 已经在 public 组里了,更正了一下配置,已经可以下载了,不过特别慢(可能依赖的 jar 比较多)。
    szq8014
        6
    szq8014  
       2019-11-08 17:13:36 +08:00   ❤️ 1
    仓库有类型的,有 proxy/hosted/group
    public 那个就是一个组,里面可以配置多个 proxy 或 hosted.
    你建一个 hosted 用于上传私有 jar 包,都加进 public 里面就可以统一通过 public 来访问了。


    结贴,散花
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   897 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 21:19 · PVG 05:19 · LAX 14:19 · JFK 17:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.