• Maven不能下载SNAPSHOT包但是能下载RELEASE包的解决办法


      在使用过程中,Maven默认配置是不能下载SNAPSHOT包的,这是基于一种代码稳定性进行考量得出的结论。引入SNAPSHOT包最大的问题就是,由于SNAPSHOT允许重复上传,所以引用一个这样的包开发的代码有可能在使用过程中会频繁出现接口变更,这会导致开发者疑惑,并不清楚究竟是什么引发的问题。但是在自建项目中,这个特性又非常有用,尤其是需要新加接口时,每加个接口都发布一个release版本显然不合理。而同一团队基于一个SNAPSHOT进行开发显然沟通成本极小,可以支持频繁迭代和更改,发布模块显然比通过git subtree引用其他代码来的更简洁更模块化,适合团队内部开发使用。

      目前我们常用的修改仓库方式是在settings里新建一个mirror如下:

        <mirrors>
            <mirror>
                <id>nexus</id>
                <name>private maven</name>
                <url>http://xxxxxx:8081/repository/maven-public/</url>
                <mirrorOf>*</mirrorOf>            
            </mirror>
        </mirrors>

      这种方式是引入外部mirror的时候使用的,如果要下载SNAPSHOT包,此种方式并不能满足要求,可以将这段配置注释掉,不影响私有仓库配置。我们可以手工配置profile的方式拉取仓库中的SNAPSHOT包,具体配置如下:

        <profiles>
            <profile>
                <id>nexus</id>
                <repositories>
                    <repository>
                        <id>central</id>
                        <name>private maven</name>
                        <url>http://xxxxxxx:8081/repository/maven-public/</url>
                        <releases>
                            <enabled>true</enabled>
                        </releases>
                        <snapshots>
                            <enabled>true</enabled>
                        </snapshots>
                    </repository>
                </repositories>
                <pluginRepositories>
                    <pluginRepository>
                        <id>central</id>
                        <name>private maven</name>
                        <url>http://xxxxxx:8081/repository/maven-public/</url>
                        <releases>
                            <enabled>true</enabled>
                        </releases>
                        <snapshots>
                            <enabled>true</enabled>
                        </snapshots>
                    </pluginRepository>
                </pluginRepositories>
            </profile>
        </profiles>
        
        <activeProfiles>
            <activeProfile>nexus</activeProfile>
        </activeProfiles>

      使用snapshots enabled启用SNAPSHOT包下载,并一定要把对应的profile ID加入到activeProfiles中,这样就可以提供SNAPSHOT服务了。

      PS:SNAPSHOT稳定了记得发布个release版本,毕竟发布多了可能忘了SNAPSHOT是什么版本了。

  • 相关阅读:
    单例模式
    js事件
    oracle_to_excel
    jquery_2
    jquery_1
    4.linux 复制,删除,重命名
    一个tomcat下部署多个springboot项目
    3.centos7 安装oracle
    桥接模式
    组合模式
  • 原文地址:https://www.cnblogs.com/gaoze/p/10792174.html
Copyright © 2020-2023  润新知