Downloading dependencies into a folder

Some projects may have a requirement for all the dependencies to be made available, say, in a folder. This could be to archive the dependencies used in a particular version of the build.

How to do it...

Use the following steps to download dependencies in the target/dependency folder:

  1. Let us open the demo project that we used in the previous recipe.
  2. Run the following command:
    mvn dependency:copy-dependencies
    
  3. See the output in the target/dependency folder:
    How to do it...

How it works...

The copy-dependencies goal of the Maven Dependency plugin copies over all the dependencies used in the project, including transitive dependencies, to target/dependency folder of the project.

There's more...

This goal takes several parameters to handle various use cases, such as copying pom files of the dependencies, copying parent poms, preserving the folder structure of the repository, and so on.

The folder location can be changed by passing the following argument:

mvn dependency:copy-dependencies -DoutputDirectory=dependencies

The dependencies will now be copied over to the dependencies folder instead of the default target/dependency folder.

The folder structure of the repository can be preserved and the poms of the dependencies can be copied over by running the following command:

mvn dependency:copy-dependencies -Dmdep.copyPom=true Dmdep.useRepositoryLayout=true

The resultant folder structure will be similar to the repository layout as shown in the following screenshot:

There's more...
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.189.199