Maven依赖版本号引发的血案

项目版本升级用了relase版本,但是发布以后,依赖的jar包在编译以后的lib目录还是旧版本。

原因是snapshot版本每次发布都会更新远程和本地仓库的文件,但是release版本会先在本地版本库中检查,如果存在就使用本地版本库的,没有才拉取远程仓库的。同样的,release版本的代码在远程仓库也是不会更新的。

那么当发现relase版本的依赖有问题时该怎么办呢?

下面是可以解决问题的几个方案。

  1. 将版本号升级。 新的版本号会在远程仓库生成新的文件,本地仓库会重新下载。

  2. 将本地和远程仓库中的旧版本删除,重新打包上去。

  3. 更改settings.xml,将updatePolicy改为always。

<profile>
    <id>nexus</id>
    <repositories>
        <repository>
            <id>central</id>
            <url>http://central</url>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </repository>
    </repositories>
</profile>
  1. maven执行打包命令的时候加上 -U 命令强制下载所有依赖的jar包
$ mvn clean install
……
[INFO] --- maven-dependency-plugin:2.1:copy-dependencies (copy-dependencies) @ demo ---
[INFO] aopalliance-1.0.jar already exists in destination.
[INFO] c3p0-0.9.1.1.jar already exists in destination.
[INFO] cglib-3.2.5.jar already exists in destination.
[INFO] druid-1.0.31.jar already exists in destination.
[INFO] fastjson-1.2.31.jar already exists in destination.
[INFO] jackson-annotations-2.5.0.jar already exists in destination.
[INFO] jackson-core-2.5.0.jar already exists in destination.
[INFO] jackson-databind-2.5.0.jar already exists in destination.
[INFO] commons-beanutils-1.8.3.jar already exists in destination.
[INFO] commons-codec-1.2.jar already exists in destination.
[INFO] commons-collections-3.2.1.jar already exists in destination.
[INFO] commons-fileupload-1.3.1.jar already exists in destination.
[INFO] commons-httpclient-3.1.jar already exists in destination.
[INFO] commons-io-2.2.jar already exists in destination.
[INFO] commons-lang-2.5.jar already exists in destination.
[INFO] commons-logging-1.1.3.jar already exists in destination.
[INFO] jstl-1.2.jar already exists in destination.
[INFO] log4j-1.2.17.jar already exists in destination.
[INFO] mysql-connector-java-5.1.40.jar already exists in destination.
[INFO] thumbnailator-0.4.8.jar already exists in destination.
[INFO] ehcache-core-2.6.8.jar already exists in destination.
[INFO] ezmorph-1.0.6.jar already exists in destination.
[INFO] json-lib-2.4-jdk15.jar already exists in destination.
[INFO] ant-1.9.6.jar already exists in destination.
[INFO] ant-launcher-1.9.6.jar already exists in destination.
[INFO] httpclient-4.5.7.jar already exists in destination.
[INFO] httpcore-4.4.11.jar already exists in destination.
[INFO] shiro-core-1.2.2.jar already exists in destination.
[INFO] shiro-web-1.2.2.jar already exists in destination.
[INFO] aspectjweaver-1.8.9.jar already exists in destination.
[INFO] mybatis-3.2.3.jar already exists in destination.
[INFO] mybatis-spring-1.3.1.jar already exists in destination.
[INFO] asm-5.2.jar already exists in destination.
[INFO] lombok-1.16.16.jar already exists in destination.
[INFO] quartz-2.2.1.jar already exists in destination.
[INFO] slf4j-api-1.7.20.jar already exists in destination.
[INFO] slf4j-log4j12-1.7.20.jar already exists in destination.
[INFO] spring-aop-4.2.5.RELEASE.jar already exists in destination.
[INFO] spring-beans-4.2.5.RELEASE.jar already exists in destination.
[INFO] spring-context-4.2.5.RELEASE.jar already exists in destination.
[INFO] spring-context-support-4.2.5.RELEASE.jar already exists in destination.
[INFO] spring-core-4.2.5.RELEASE.jar already exists in destination.
[INFO] spring-expression-4.2.5.RELEASE.jar already exists in destination.
[INFO] spring-jdbc-4.2.5.RELEASE.jar already exists in destination.
[INFO] spring-test-4.2.5.RELEASE.jar already exists in destination.
[INFO] spring-tx-4.2.5.RELEASE.jar already exists in destination.
[INFO] spring-web-4.2.5.RELEASE.jar already exists in destination.
[INFO] spring-webmvc-4.2.5.RELEASE.jar already exists in destination.
[INFO] standard-1.1.2.jar already exists in destination.
……

转载于:https://my.oschina.net/ijiangtao/blog/3028107

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值