0
votes

I have following project structure:

  1. Project "parent-project" does not have any source file and has subprojects as "junit-wrapper","child1-test" and "child2-test".
  2. Subproject "junit-wrapper" has only java source inside src/main/java and this is basically created to wrap all the dependencies and binaries under the hierarchy "parent-project".
  3. Subproject "child1-test" and "child2-test" has no source files and only contains subprojects as "child1-env" and "child2-env".
  4. Subproject "child1-env" and "child2-env" has only junits inside src/test/java.

I want to build a super jar(within junit-wrapper) by building parent pom.xml

I hope this is possible by using maven-assembly-plugin but don't know how to configure this in pom.xml. what should be my pom.xml or assembly.xml(on using plugin) entries in order to ensure this is achieved?

please suggest.

thanks.

2
Dou you like to reuse the classed from the junit-wrapper in other modules/projects? - khmarbaise

2 Answers

2
votes

To create a jar which contains test-classes the best solution is to use the maven-jar-plugin like this:

<project>
  <build>
    <plugins>
     <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-jar-plugin</artifactId>
       <version>2.2</version>
       <executions>
         <execution>
           <goals>
             <goal>test-jar</goal>
           </goals>
         </execution>
       </executions>
     </plugin>
    </plugins>
  </build>
</project>

In other modules you can use the test-jar via the following dependency:

<project>
  ...
  <dependencies>
    <dependency>
      <groupId>com.myco.app</groupId>
      <artifactId>foo</artifactId>
      <version>1.0-SNAPSHOT</version>
      <type>test-jar</type>
      <scope>test</scope>
    </dependency>
  </dependencies>
  ...
</project>
0
votes

You will get your "uber-jar" when you include this configuration into the pom file of junit-wrapper:

<build>
  <plugins>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <version>2.2.1</version>
      <executions>
        <execution>
          <id>make-assembly</id>
          <phase>package</phase>
          <goals>
            <goal>single</goal>
          </goals>
          <configuration>
            <descriptorRefs>
              <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

An assembly descriptor (assembly.xml) is not necessary because the jar-with-dependencies descriptor is already available within the maven-assembly-plugin. Note that you should not execute the assembly plugin before the package phase. Otherwise the code of your maven module will not get packaged into your assembly.