简体   繁体   English

IntelliJ:Build> Rebuild Project菜单项与Maven clean install

[英]IntelliJ: Build > Rebuild Project menu item versus Maven clean install

For a Maven -driven project in IntelliJ 2018, when should I choose to use… 对于IntelliJ 2018中的Maven驱动项目,我应该何时选择使用...

  • The IntelliJ 2018.1 menu item Build > Rebuild Project IntelliJ 2018.1菜单项Build > Rebuild Project
  • The Maven panel's clean and install Lifecycle items Maven面板cleaninstall Lifecycle项目

Under what circumstances is either appropriate? 在什么情况下适当?

My situation is a Vaadin 8 application using the vaadin-archetype-application-multimodule Vaadin archetype . 我的情况是使用vaadin-archetype-application-multimodule Vaadin原型Vaadin 8应用vaadin-archetype-application-multimodule

The Question, Does IntelliJ Build > Rebuild Project invoke maven? 问题, IntelliJ Build> Rebuild Project是否会调用maven? has a single Answer that says the Rebuild Project does not invoke Maven at all. 有一个答案Rebuild Project根本不调用Maven。 But no guidance is given on when to use route versus the other. 但没有给出关于何时使用路线与其他路线的指导。

Well, if you make substancial changes within a pom.xml file (new plugins, new modules within a multi-module project), you'd better run "mvn clean install". 好吧,如果您在pom.xml文件(新插件,多模块项目中的新模块)中进行了更改,您最好运行“mvn clean install”。 I personally never use the "Rebuild Project" within a Maven project. 我个人从不在Maven项目中使用“重建项目”。 usually I just "make" the project so the class files are updated, or I start a real Maven build to get new / updated dependencies. 通常我只是“制作”项目以便更新类文件,或者我启动一个真正的Maven构建来获取新的/更新的依赖项。

The third important option (for me) is the "Reimport all Maven projects" option, which is quite useful if a pure Maven build runs fine, but IntelliJ still thinks that there is something wrong within your project. 第三个重要选项(对我来说)是“重新导入所有Maven项目”选项,如果纯Maven构建运行良好,这非常有用,但IntelliJ仍然认为您的项目中存在错误。

When you have a multi-module Maven project and: 当您有一个多模块Maven项目时:

  • Start your tests and application programmatically by IntelliJ (Main.java): 通过IntelliJ(Main.java)以编程方式启动测试和应用程序:

    You do not need to use Maven at all, no clean, no install, only Make . 你根本不需要使用Maven,没有干净,没有安装,只有Make And Rebuild when the project gets screwed up. 当项目搞砸时Rebuild

    Click Reimport when you change dependencies or someone deploys a new dependency snapshot to your repo. 更改依赖关系时单击Reimport ,或者有人将新的依赖关系快照部署到您的存储库。 If IntelliJ refuses to download the snapshot, then try mvn clean install . 如果IntelliJ拒绝下载快照,请尝试mvn clean install

    And why would you even do all that? 你为什么要做那些呢? It is faster and more user friendly. 它更快,更友好。

  • Start your tests and application by Maven in IntelliJ (mvn jetty:run): 通过IntelliJ中的Maven开始测试和应用程序(mvn jetty:run):

    You have to install your modules which are as dependencies for the module on which you start your application ( mvn jetty:run ), because Maven does not use your compiled output for dependencies, but takes an artifact from your remote/local repository. 您必须安装模块,这些模块作为启动应用程序的模块的依赖项( mvn jetty:run ),因为Maven不会将编译后的输出用于依赖项,而是从远程/本地存储库中获取工件。 For this case Make/Rebuild is useless, you have to use mvn (clean) install . 对于这种情况, Make/Rebuild是无用的,你必须使用mvn (clean) install

    If you have made changes only in a module on which you run mvn jetty:run then you do not need to use package/install , but sometimes you have to use clean or Rebuild as Maven does not remove deleted resources. 如果您仅在运行mvn jetty:run的模块中进行了更改mvn jetty:run则不需要使用package/install ,但有时您必须使用cleanRebuild因为Maven不会删除已删除的资源。

    Make is good for hot-swap - for that reason, it is a good idea to import all Maven projects you develop and on which you depend into a single IntelliJ project. Make适用于热插拔 - 因此,最好将您开发的所有Maven项目导入到单个IntelliJ项目中。 Initial Rebuild comes handy, because without it, Make would compile the whole project instead of only changed classes, then possibly failing hot-swap or it would just take too long. 初始Rebuild很方便,因为没有它, Make会编译整个项目而不是只更改类,然后可能会失败热插拔或者它只需要太长时间。 Or you could just click Make before you run your application, but it could leave some old resources created by Maven in compiled output, Rebuild would take care of that. 或者你可以在运行应用程序之前单击Make ,但它可能会留下Maven在编译输出中创建的一些旧资源, Rebuild会处理这个问题。

    You can also configure your app-server to restart/reload when it detects updated files from Make or Rebuild - certainly faster than restarting the JVM or compiling by Maven, but you might like to disable that and use only hot-swap, which is still way faster if you do small changes. 您还可以将app-server配置为在从MakeRebuild检测到更新文件时重新启动/重新加载 - 当然比重新启动JVM或由Maven编译更快,但是您可能希望禁用它并仅使用热交换,这仍然是如果做一些小改动,速度会更快。

Either way you might want to take a look at Maven Helper plugin for IntelliJ , it will make things way easier in big projects. 无论哪种方式,您可能想要查看IntelliJ的Maven Helper插件 ,它将使大型项目中的事情变得更容易。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM