пятница, 15 марта 2013 г.

Maven: specify folder for jars

Sometimes you need to download jars, which were in your "dependencies" block into specified directory.
For this task you may use this approach: in "plugins" part of your pom.xml add such block:


<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>


This will copy all jars into target/lib folder after run command : mvn generate-sources
If you want to specify directory from command line, you can do such thing:


<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${path_to_file}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

After this, you can path patameter "path_to_file" from command line : mvn -Dpath_to_file=your_path generate-sources



author - Mikhail Sidelnikov
email: sidelnikovmike@gmail.com