Make Maven to copy dependencies into target/lib Make Maven to copy dependencies into target/lib java java

Make Maven to copy dependencies into target/lib


This works for me:

<project>  ...  <profiles>    <profile>      <id>qa</id>      <build>        <plugins>          <plugin>            <artifactId>maven-dependency-plugin</artifactId>            <executions>              <execution>                <phase>install</phase>                <goals>                  <goal>copy-dependencies</goal>                </goals>                <configuration>                  <outputDirectory>${project.build.directory}/lib</outputDirectory>                </configuration>              </execution>            </executions>          </plugin>        </plugins>      </build>    </profile>  </profiles></project>


mvn install dependency:copy-dependencies 

Works for me with dependencies directory created in target folder. Like it!


The best approach depends on what you want to do:

  • If you want to bundle your dependencies into a WAR or EAR file, then simply set the packaging type of your project to EAR or WAR. Maven will bundle the dependencies into the right location.
  • If you want to create a JAR file that includes your code along with all your dependencies, then use the assembly plugin with the jar-with-dependencies descriptor. Maven will generate a complete JAR file with all your classes plus the classes from any dependencies.
  • If you want to simply pull your dependencies into the target directory interactively, then use the dependency plugin to copy your files in.
  • If you want to pull in the dependencies for some other type of processing, then you will probably need to generate your own plugin. There are APIs to get the list of dependencies, and their location on disk. You will have to take it from there...