Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy dependency of a maven project to specific folder

I am trying to get all the jar required for a maven project inside a particular folder.

I have used mvn dependency:copy-dependencies command.

It gives me the required jar files inside taget/dependeny folder.

Although I can use move or copy coommand to copy those jars to another directory, is there any way to copy the dependencies in directory of my choice directly?

like image 312
Bopsi Avatar asked Oct 08 '15 10:10

Bopsi


People also ask

How do I download Maven dependencies to local?

You can use the Maven Dependency Plugin to download dependencies. Run mvn dependency:copy-dependencies , to download all your dependencies and save them in the target/dependency folder. You can change the target location by setting the property outputDirectory .

What is Maven copy-dependencies?

Full name: org.apache.maven.plugins:maven-dependency-plugin:3.3.0:copy-dependencies. Description: Goal that copies the project dependencies from the repository to a defined location.

How do I force Maven to download dependencies from remote repository?

We can use -U/--update-snapshots flag when building a maven project to force maven to download dependencies from the remote repository. Here, -U,--update-snapshots : Forces a check for missing releases and updated snapshots on remote repositories.


1 Answers

You need to use the outputDirectory property to define the required location where you would like the jars to be copied to.

Here is an example of the configuration you would add in your POM:

<plugins>
...
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
            <execution>
                <id>copy-dependencies</id>
                <phase>package</phase>
                <goals>
                    <goal>copy-dependencies</goal>
                </goals>
                <configuration>
                    <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
                </configuration>
            </execution>
        </executions>
    </plugin>
    ...
</plugins>

Alternatively you can pass this configuration directly via the command line:

mvn -DoutputDirectory=alternativeLocation dependency:copy-dependencies 
like image 85
DB5 Avatar answered Oct 06 '22 00:10

DB5