Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify non-compile dependencies in Maven and package them as resources

Tags:

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.

like image 334
Thilo Avatar asked Jun 11 '09 13:06

Thilo


2 Answers

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>
like image 149
Cuga Avatar answered Oct 12 '22 09:10

Cuga


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

like image 45
Gareth Davis Avatar answered Oct 12 '22 07:10

Gareth Davis