Search code examples
javamavenmaven-3maven-plugin

Maven: To get latest release mvn clean then mvn package working fine but mvn clean package not


I have single project setup where I am using versions-maven-plugin to get latest release.

When I ran mvn clean before mvn package, getting updated message which specify

[INFO] Updated old_version:jar:0 to version new_version.

But when I ran mvn clean package together then maven not able to get latest version and I got this error message

Could not find artifact old_version:jar:0

Why is this happening? If maven follows the order of execution then it should clean which updates the version first then package. Any idea why mvn clean package command is not working.


Solution

  • Running mvn clean and then mvn package is not exactly the same as mvn clean package.

    The reason: Maven resolves all dependencies before it runs any of the lifecycles.

    So if you run mvn clean and then mvn package you get:

    • resolves dependencies
    • updates your dependecy
    • resolves dependencies
    • package

    but if you run mvn clean package, you get:

    • resolves dependencies
    • updates your dependency
    • package (with the resolved dependencies from the beginning)

    Summarized: You cannot update and use dependencies in the same Maven run.