Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create jar with dependencies AND test-dependencies

Tags:

maven-2

How can I build a jar (with maven) which contains the test classes and the test dependencies.

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

I know I can use the jar plugin to create a jar with test classes but this doesn't contain the test dependencies.

TIA

like image 721
thehpi Avatar asked Nov 21 '11 10:11

thehpi


1 Answers

You can probably achieve by combining the maven-dependency-plugin:copyDependencies with the assembly 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>
like image 149
Stijn Geukens Avatar answered Sep 21 '22 22:09

Stijn Geukens