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

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

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


当前回答

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

其他回答

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

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

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

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

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 - dacttransitive =false -Dskip=true如果你有maven插件作为模块之一。否则,Maven将尝试重新编译它们,从而再次下载依赖项。

正如一些回答所指出的,有时您确实想要完全删除本地存储库,例如,可能有一些工件不能被清除,因为它们不再被pom引用。

如果你想把这个删除嵌入到maven阶段,比如clean,你可以使用maven-clean-plugin并通过设置访问存储库,例如:

 <plugin>
    <inherited>false</inherited>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.1</version>
    <executions>
        <execution>
            <phase>clean</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <tasks>
                    <echo>Base clean is attached to deleting local maven cache</echo>
                    <echo>${settings.localRepository}</echo>
                </tasks>
            </configuration>
        </execution>
    </executions>
</plugin>

<plugin>
    <inherited>false</inherited>
    <artifactId>maven-clean-plugin</artifactId>
    <version>3.1.0</version>
    <configuration>
        <filesets>
            <fileset>
                <directory>${settings.localRepository}</directory>
            </fileset>
        </filesets>
    </configuration>
</plugin>

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