I used both the commands to resolve dependency issues in my project. mvn -U clean compile
resolved issues. But I don't know difference between them. Please explain difference between those commands and when do I Use mvn clean compile
and mvn -U clean compile
.
mvn clean: Cleans the project and removes all files generated by the previous build. mvn compile: Compiles source code of the project. mvn test-compile: Compiles the test source code.
mvn package command will compile source code and also package it as a jar or war as per pom file and put it into the target folder(by default). mvn install command will compile and package, but it will also put the package in your local repository.
mvn package command will compile source code and also package it as a jar or war as per pom file and put it into the target folder(by default). mvn install command will compile and package, but it will also put the package in your local repository.
Maven expects a certain directory structure for your Java source code to live in and when you later do a mvn clean install , the whole compilation and packaging work will be done for you.
-U, --update-snapshots Forces a check for updated releases and snapshots on remote repositories
see here (6.1.11. Downloading and Verifying Dependencies):
-clean will clean (remove all compiled and copied resources) of your maven project target directory.
-install will do almost a full maven lifecycle like testing, compiling AND copying the new builds to your local repository.
-U you will tell maven to update your local repository's remote dependencies (usually third party dependencies) as well
-U,--update-snapshots Forces a check for updated
releases and snapshots on remote
repositories
For your information,if you execute mvn -h command in the command prompt then it will display all the options just like below. So if you need to know about any option details, you can use mvn -h command.
usage: mvn [options] [<goal(s)>] [<phase(s)>]
Options:
-am,--also-make If project list is specified, also
build projects required by the
list
-amd,--also-make-dependents If project list is specified, also
build projects that depend on
projects on the list
-B,--batch-mode Run in non-interactive (batch)
mode
-C,--strict-checksums Fail the build if checksums don't
match
-c,--lax-checksums Warn if checksums don't match
-cpu,--check-plugin-updates Ineffective, only kept for
backward compatibility
-D,--define <arg> Define a system property
-e,--errors Produce execution error messages
-emp,--encrypt-master-password <arg> Encrypt master security password
-ep,--encrypt-password <arg> Encrypt server password
-f,--file <arg> Force the use of an alternate POM
file (or directory with pom.xml).
-fae,--fail-at-end Only fail the build afterwards;
allow all non-impacted builds to
continue
-ff,--fail-fast Stop at first failure in
reactorized builds
-fn,--fail-never NEVER fail the build, regardless
of project result
-gs,--global-settings <arg> Alternate path for the global
settings file
-h,--help Display help information
-l,--log-file <arg> Log file to where all build output
will go.
-llr,--legacy-local-repository Use Maven 2 Legacy Local
Repository behaviour, ie no use of
_maven.repositories. Can also be
activated by using
-Dmaven.legacyLocalRepo=true
-N,--non-recursive Do not recurse into sub-projects
-npr,--no-plugin-registry Ineffective, only kept for
backward compatibility
-npu,--no-plugin-updates Ineffective, only kept for
backward compatibility
-nsu,--no-snapshot-updates Suppress SNAPSHOT updates
-o,--offline Work offline
-P,--activate-profiles <arg> Comma-delimited list of profiles
to activate
-pl,--projects <arg> Comma-delimited list of specified
reactor projects to build instead
of all projects. A project can be
specified by [groupId]:artifactId
or by its relative path.
-q,--quiet Quiet output - only show errors
-rf,--resume-from <arg> Resume reactor from specified
project
-s,--settings <arg> Alternate path for the user
settings file
-T,--threads <arg> Thread count, for instance 2.0C
where C is core multiplied
-t,--toolchains <arg> Alternate path for the user
toolchains file
-U,--update-snapshots Forces a check for updated
releases and snapshots on remote
repositories
-up,--update-plugins Ineffective, only kept for
backward compatibility
-V,--show-version Display version information
WITHOUT stopping build
-v,--version Display version information
-X,--debug Produce execution debug output
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With