Maven - Why after “mvn clean” I need to execute “Maven Update Project” before “mvn package”?

后端 未结 3 618
北荒
北荒 2020-12-31 11:34

I\'m making some tests and I would like to understand why after execute the command mvn clean I need to execute \"Maven > Update Project\" before run mvn

相关标签:
3条回答
  • 2020-12-31 11:56

    The Eclipse m2e plugin (this is a simplification) reads the POM file and translates it into instructions for Eclipse so that Eclipse can do its thing. Because Eclipse is in control the whole time, your view gets updated correctly and things are pretty smooth. Some more advanced Maven actions with plugins are not supported by m2e, and so those actions just won't happen. Some simple stuff, like the classpath is different from how Maven does things -- m2e uses the "test" classpath no matter what because Eclipse can't predict what you'll want to run.

    On the other hand, performing "Run as > Maven ..." actually calls Maven, a program completely outside of Eclipse, and asks it to run. Eclipse doesn't automatically know when files have been created or deleted by Maven.

    I would generally stay away from the "Run as > Maven" commands. The integration is poor, the Eclipse console interface is ugly, it's just easier to call mvn from the command line if you need to run specific Maven goals.

    If you just want to develop a Maven project, I find the m2e integration works very well. I use Jenkins to handle the packaging and deployment for me, so I'm only using Eclipse to edit and test my code.

    0 讨论(0)
  • 2020-12-31 12:02

    Here is what happens:

    1. mvn clean deletes the target directory
    2. mvn package performs some work, but then encounters a compilation error due to a missing dependency. That's why the target folder is in error.
    3. Running Maven > Update Project in Eclipse causes Eclipse to perform its own compilation, separate from Maven. Eclipse has a different classpath than Maven, so its compilation succeeds. Now the target directory has all the compiled classes.
    4. Re-running mvn package now succeeds, because it finds all the classes already compiled and doesn't need to perform any compilation.

    Ultimately, the problem is in the project configuration in pom.xml. I had the same problem, and after adding the missing dependency I successfully compiled project with Maven.

    0 讨论(0)
  • 2020-12-31 12:02

    It will update the files if any new updates avialable.you can use maven install after maven clean

    0 讨论(0)
提交回复
热议问题