简体   繁体   English

在Maven,为什么要运行'mvn clean'?

[英]In Maven, Why Run 'mvn clean'?

I am wondering what the major difference between running mvn compile and mvn clean compile are, in practicality. 我想知道运行mvn compilemvn clean 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? 我理解实际的区别是, mvn clean compile删除了所有生成的文件并从头开始,但为什么我们要这样做呢? I can assume mvn compile will regenerate files if it's necessary, right? 我可以假设mvn compile会在必要时重新生成文件,对吧?

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 ,那么编译后的文件仍然存在,这通常不会成为问题,但我想是可以的。

For example: If you rename a class, the previous compiled version will remain in target/classes until you run clean . 例如:如果重命名一个类,则先前编译的版本将保留在target/classes直到您运行clean This maybe completely harmless, but it could cause issues if it is autodetected by classpath scanning and the like. 这可能完全无害,但如果通过类路径扫描等自动检测它可能会导致问题。

Certain plugins require a clean in order to work properly. 某些插件需要clean才能正常工作。 For instance (at least in Maven 2), the maven-war-plugin explodes each dependent WAR into an existing directory tree. 例如(至少在Maven 2中), maven-war-plugin每个依赖WAR分解为现有目录树。 It requires a clean to get rid of files that have been removed from the dependent WARs. 它需要一个clean去掉已从依赖WAR中删除的文件。

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 . 另一个问题是,当您重命名一个类时,旧的编译版本可以在构建树中挂起,并将包含在JAR文件中,等等......直到您运行mvn clean

I can assume "mvn compile" will regenerate files if it's necessary, right? 我可以假设“mvn compile”会在必要时重新生成文件,对吧?

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. 例如,有一些不受支持的插件,其目的是驱动Eclipse EMF代码生成器。

on Maven, each time you want to compile, its best practice to run "mvn clean". 在Maven上,每次你想编译时,最好的做法是运行“mvn clean”。 it clears out the existing classes that you compiled from last compile. 它清除了您从上次编译中编译的现有类。 if you don't want to run 3 lines, just do "mvn test" after "mvn clean". 如果你不想运行3行,只需在“mvn clean”之后执行“mvn test”。 you don't have to always do "mvn compile". 你不必总是做“mvn编译”。

If you don't do clean compile then it means you are still allowing to work with some obsolete classes. 如果你不进行干净编译,那么这意味着你仍然允许使用一些过时的类。 If your module suppose to migrate to new class then even you missed that, there won't be any compilation error due to old class exist in target/classes. 如果你的模块想要迁移到新类,那么即使你错过了,由于目标/类中存在旧类,也不会有任何编译错误。 This will remain unnoticed till same module is built at some other place/machine with clean compile goal. 直到在具有干净编译目标的其他地方/机器上构建相同模块时,这将保持不被注意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Maven:MVN clean和MVN软件包分别运行,但一起运行会产生问题 - Maven: mvn clean and mvn package individually run but together gives issue 无法运行mvn clean - Cannot run mvn clean Maven命令“ mvn clean jetty:run”和其他mvn命令在Eclipse中不起作用 - Maven command “mvn clean jetty:run” and other mvn commands are not working in Eclipse maven clean install等于mvn clean并在mvn安装后? - Maven clean install is equal mvn clean and after mvn install? 无法运行MVN清理任务 - Cannot run mvn clean task 如何配置maven hbm2hbmxml和hbm2java在mvn clean install中一个接一个地运行 - How to configure maven hbm2hbmxml and hbm2java to run one after the other in mvn clean install Maven命令mvn clean verify不会激活故障保护以运行集成测试 - Maven command mvn clean verify does not activate Failsafe to run integration-tests Maven 未使用 mvn clean verify 运行 cucumber 测试 - Maven not running cucumber tests with mvn clean verify Maven:要获得最新版本的 mvn clean 然后 mvn package 工作正常但 mvn clean package 不行 - Maven: To get latest release mvn clean then mvn package working fine but mvn clean package not 使用“mvn verify”而不是“mvn clean verify”运行连续构建是否安全 - Is it safe to run continuous builds with “mvn verify” instead of “mvn clean verify”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM