Create a jar with dependencies and test dependencies

How can I create a jar (with maven) that contains test classes and test dependencies.

I know how to create a jar with dependencies (using the build plugin) for classes and dependencies for the "main" classes, but I need test classes and test dependencies.

I know that I can use the jar plugin to create jar with test classes, but this does not contain test dependencies.

TIA

+5
source share
1 answer

You can probably achieve this by combining the maven-dependency: copyDependencies plugin with the build plugin.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <executions>
    <execution>
      <id>copy-dependencies</id>
      <phase>process-resources</phase>
      <goals>
        <goal>copy-dependencies</goal>
      </goals>
      <configuration> <!-- by default all scopes are included -->
        <!-- copy all deps to target/lib -->
        <outputDirectory>${project.build.directory}/lib</outputDirectory>
      </configuration>
    </execution>
  </executions>
</plugin>
<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  ...
</plugin>

Your descriptor:

<assembly>
  <fileSets>
    <fileSet>
      <directory>${project.build.directory}/lib</directory>
      <outputDirectory>/</outputDirectory>
      <includes>
        <include>*.*</include>
      </includes>
    </fileSet>
  </fileSets>
</assembly>
+1
source

All Articles