views:

584

answers:

3

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.

+2  A: 

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

Gareth Davis
+1  A: 

Since you say you want to end up with a jar, the assembly plugin with a custom assembly descriptor would probably solve this.

Add a <dependencySet> and specify the <unpack> option to ensure those external artifacts get flattened out inside your jar.

itzgeoff
+2  A: 

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>
Cuga