I see maven-dependency-plugin
does this; however, it seems to copy everything (including test jars) to the destination directory. Anyone know how to configure this plugin to exclude test jars?
When you run a Maven build, then Maven automatically downloads all the dependency jars into the local repository. It helps to avoid references to dependencies stored on remote machine every time a project is build.
If you want do download them all, you can try using mvn dependency:copy-dependencies . Then, you'll find all project dependencies in target/dependencies directory of your project. This also includes transitive dependencies. To add them all as eclipse dependencies, you may want to try maven-eclipse-plugin .
The dependency:copy goal can also be used to copy the just built artifact to a custom location if desired. It must be bound to any phase after the package phase so that the artifact exists in the repository.
Mike answered their own question in a comment above. I think Mike's use case is similar to mine where I want to copy all of the jars I depend upon as well as my own jar in order to create a directory hierarchy sufficient to execute the program without including those dependencies directly into my own jar.
The answer to achieve this is:
<includeScope>compile</includeScope>
This directive goes into the section of the pom.xml for the maven-dependency plugin. For example:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.4</version> <executions> <execution> <id>copy-dependencies</id> <phase>prepare-package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> <includeScope>compile</includeScope> </configuration> </execution> </executions> </plugin>
excludeScope won't work because excluding test aborts the build and excludes all possible scopes. Instead the included scope needs to be adjusted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With