Maven – Copy A Dependency

If you want to copy a Maven project dependency to a specific location, the maven-dependency-plugin could help.

For example. if you want to copy the log4j-1.2.15.jar to the project target folder during mvn install. you can use the following piece of code.

<build>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-dependency-plugin</artifactId>
			<executions>
				<execution>
					<id>copy-installed</id>
					<phase>install</phase>
					<goals>
						<goal>copy</goal>
					</goals>
					<configuration>
						<artifactItems>
							<artifactItem>
								<groupId>log4j</groupId>
								<artifactId>log4j</artifactId>
								<version>1.2.15</version>
								<type>jar</type>
							</artifactItem>
						</artifactItems>
						<outputDirectory>target</outputDirectory>
					</configuration>
				</execution>
			</executions>
		</plugin>
	</plugins>
</build>

Done =)

Reference:

2 thoughts on “Maven – Copy A Dependency”

  1. Kudos, hats off and many, many thanks on top of it !!!

    I see you like to dance… here is a small gift for you:

    Greetings from Serbia !

    Like

Leave a reply to Dejan Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.