最近,Apache Maven似乎遇到了缓存问题。使用Windows Vista或Windows 7在我们的项目上执行干净安装,有时会产生具有与以前构建相同数据的工件,即使较新的工件的文件应该已经更新。

有没有办法清除这个缓存,迫使maven总是触发应该构建的本地工件的干净构建?

特别是,我们在使用war插件构建web应用程序时遇到了问题。Maven版本是3.0.3。War插件版本为2.1.1。


当前回答

若要清除本地缓存,请尝试使用依赖项插件。

mvn dependency:purge-local-repository: This is an attempt to delete the local repository files but it always goes and fills up the local repository after things have been removed. mvn dependency:purge-local-repository -DreResolve=false: This avoids the re-resolving of the dependencies but seems to still go to the network at times. mvn dependency:purge-local-repository -DactTransitively=false -DreResolve=false: This was added by Paweł Prażak and seems to work well. I'd use the third if you want the local repo emptied, and the first if you just want to throw out the local repo and get the dependencies again.

其他回答

若要清除本地缓存,请尝试使用依赖项插件。

mvn dependency:purge-local-repository: This is an attempt to delete the local repository files but it always goes and fills up the local repository after things have been removed. mvn dependency:purge-local-repository -DreResolve=false: This avoids the re-resolving of the dependencies but seems to still go to the network at times. mvn dependency:purge-local-repository -DactTransitively=false -DreResolve=false: This was added by Paweł Prażak and seems to work well. I'd use the third if you want the local repo emptied, and the first if you just want to throw out the local repo and get the dependencies again.

删除c:\Users\<username>\。M2 \资源库的手。

这里有一些命令可以用于清理

 1. mvn clean cache   
 2. mvn clean install 
 3. mvn clean install -Pclean-database

此外,从.m2中删除存储库文件夹也会有所帮助。

使用mvn dependency:purge-local-repository - dacttransitive =false -Dskip=true如果你有maven插件作为模块之一。否则,Maven将尝试重新编译它们,从而再次下载依赖项。

您是否检查/更改了settings.xml中存储库的updatePolicy设置。

此元素指定更新应该尝试发生的频率。 Maven将比较本地POM的时间戳(存储在存储库中) maven-元数据文件)到远程。选择是:总是,每天 (默认值),间隔:X(其中X为整数,单位为分钟)或从不。

试着把它设置为always。