本文介绍了在Maven,为什么要运行'mvn clean'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在实际中运行 mvn compile mvn clean compile 之间的主要区别是什么。

I am wondering what the major difference between running mvn compile and mvn clean compile are, in practicality.

我明白实际的区别是, mvn clean compile 删除所有生成的文件并从头开始,但为什么我们要这样做呢?我可以假设 mvn compile 会在必要时重新生成文件,对吗?

I understand what the actual difference is, that mvn clean compile deletes all the generated files and starts again from scratch, but why would we want to do this? I can assume mvn compile will regenerate files if it's necessary, right?

我在项目中注意到的一件事是如果你已经删除了一个源文件,而没有运行 clean ,那么编译后的文件仍然存在,这通常不会有问题,但我想是的。

One thing I noticed in my project was that if you had deleted a source file, without running clean, the compiled file remains, which usually wouldn't be a problem, but could be I suppose.

推荐答案

某些插件需要 clean 才能正常工作。例如(至少在Maven 2中), maven-war-plugin 将每个依赖WAR分解为现有目录树。它需要 clean 来删除已从依赖WAR中删除的文件。

Certain plugins require a clean in order to work properly. For instance (at least in Maven 2), the maven-war-plugin explodes each dependent WAR into an existing directory tree. It requires a clean to get rid of files that have been removed from the dependent WARs.

另一个问题是当你重命名一个类时,旧的编译版本可以在构建树中闲逛,并将包含在JAR文件中,等等......直到你运行 mvn clean 。 / p>

Another problem is that when you rename a class, the old compiled version can hang around in the build tree, and will get included in JAR files, etcetera ... until you run mvn clean.

对于主流插件,这是一个公平的假设。但是,如果您使用插件生成源代码组件,我会仔细查看文档以及放置生成的源代码的位置。例如,有一些不受支持的插件,其目的是驱动Eclipse EMF代码生成器。

For mainstream plugins, that is a fair assumption. However, if you are using a plugin to generate source code components, I'd look carefully at the documentation, and at where you put the generated source code. For instance, there are a couple of unsupported plugins whose purpose is to drive the Eclipse EMF code generator.

这篇关于在Maven,为什么要运行'mvn clean'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 11:59