nguyen dang Thanh
nguyen dang Thanh

Reputation: 94

Different between mvn clean, mvn install and mvn clean install

I'm using Maven for my project. It is not an issue if my project doesn't use some local resources. So that I'm following this guide https://stackoverflow.com/a/61576687/6720896 to copy my local jar to local maven repository and validated by Maven.

As you can see, in the maven-install-plugin, I'm setting to install local repository at clean phase. It means by mvn clean, maven will copy my jar to maven local repository.

The problem is, if I run mvn clean and mvn install by two commands separately => there is no problem If i run mvn clean install => the build is failed as the log

Caused by: org.apache.maven.project.DependencyResolutionException: Could not resolve dependencies for project xxxx:xxxx:war:0.0.1-SNAPSHOT: Failure to find org.xxxx:xxxx-ws:jar:1.0.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced

Seem like by default, maven always execute following order: validate > compile > clean > install. I also tried with 'mvn clean validate' but the error still occurs.

Thank you for reading.

Upvotes: 6

Views: 20869

Answers (1)

J Fabian Meier
J Fabian Meier

Reputation: 35785

The question is not really clear, but my interpretation is as follows:

The OP wants to automatically add a dependency to the local repository by using install:install-file. Then the OP wants to use that dependency. This works if mvn clean and mvn install are run separately, but not if one runs mvn clean install.

The reason is as follows:

Maven resolves dependencies at the beginning of the process. So dependencies are already resolved before the clean of mvn clean install is executed.

This especially implies that you cannot install and resolve a dependency in the same Maven run.

If, though, you first run mvn clean (which installs the dependency) and then mvn install (which uses the dependency), everything is fine.

Upvotes: 5

Related Questions