项目版本升级用了relase版本,但是发布以后,依赖的jar包在编译以后的lib目录还是旧版本。
原因是snapshot版本每次发布都会更新远程和本地仓库的文件,但是release版本会先在本地版本库中检查,如果存在就使用本地版本库的,没有才拉取远程仓库的。同样的,release版本的代码在远程仓库也是不会更新的。
那么当发现relase版本的依赖有问题时该怎么办呢?
下面是可以解决问题的几个方案。
-
将版本号升级。 新的版本号会在远程仓库生成新的文件,本地仓库会重新下载。
-
将本地和远程仓库中的旧版本删除,重新打包上去。
-
更改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>
- 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.
……