I need to build a jar file that includes (other, external projects') Maven artefacts.
The artefacts are to be included just like stuff in src/main/resources
, without any processing. Even though they happen to be jar files themselves, they are not compile time dependencies for my code and should not be added to the classpath, at neither the compile, the test, or the runtime stages.
I can get this done by downloading the files and placing them into src/main/resources
, but I would rather have them resolved using the Maven repository.
Here's an example of what you can add to your pom-- it'll copy the artifact with the specified ID from the specified project into the location you specify.
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>id.of.the.project.group.to.include</groupId>
<artifactId>id-of-the-project's-artifact-to-include</artifactId>
<version>${pom.version}</version>
</artifactItem>
</artifactItems>
<includeArtifactIds>id-of-the-project's-artifact-to-include</includeArtifactIds>
<outputDirectory>${project.build.directory}/etc-whatever-you-want-to-store-the-dependencies</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
You could use the dependency plugin to download and put your required artefacts into the target/classes
directory during the process-resources phase.
See the example usage for copying artefacts
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