在 Maven 中,为什么要运行“mvn clean"? [英] In Maven, Why Run 'mvn clean'?

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

问题描述

我想知道在实践中运行 mvn compilemvn 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.

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.

如果有必要,我可以假设mvn compile"会重新生成文件,对吗?

I can assume "mvn compile" will regenerate files if it's necessary, right?

对于主流插件,这是一个合理的假设.但是,如果您使用插件生成源代码组件,我会仔细查看文档,以及您放置生成的源代码的位置.例如,有一些不受支持的插件旨在驱动 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"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆