I want to create a jar file with my main java project and all of it\'s dependencies. so I created the following plugin definition in the pom file:
That is normal: you configured a special execution of the maven-dependency-plugin
, named copy-dependencies
, however, invoking the goal dependency:copy-dependencies
directly on the command line creates a default execution, which is different than the one you configured. Thus, your configuration isn't taken into account.
In Maven, there are 2 places where you can configure plugins: either for all executions (using
at the
level) or for each execution (using
at the
level).
There are several ways to solve your issue:
Move the
outside of the
, and make it general for all executions. You would have:
maven-dependency-plugin
2.5.1
runtime
${project.build.directory}/dependency-jars/
Note that, with this, all executions of the plugin will use this configuration (unless overriden inside a specific execution configuration).
Execute on the command line a specific execution, i.e. the one you configured. This is possible since Maven 3.3.1 and you would execute
mvn dependency:copy-dependencies@copy-dependencies
The @copy-dependencies
is used to refer to the
of the execution you want to invoke.
Bind your execution to a specific phase of the Maven lifecycle, and let it be executed with the normal flow of the lifecycle. In your configuration, it is already bound to the package
phase with
. So, invoking mvn clean package
would work and copy your dependencies at the configured location.