tags:

views:

83

answers:

1

Hi I wanted to package the class files under target/test-classes(ie src/test/java) as one assembly. When I am running the maven command,i am getting the error: Reason: Failed to create assembly: Error creating assembly archive : You must set at least one file.

My assembly desciptor is :

  <assembly>

<id>stress-client</id>
<formats>
 <format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
 <fileSet>
  <directory>${project.build.testOutputDirectory}
  </directory>
  <includes>

   list of files to be included


  </includes>


  <outputDirectory>/</outputDirectory>

 </fileSet>
</fileSets>

i find test-classes empty.Why the test files are not getting compiled? Please help

+1  A: 

I'm guessing the assembly is trying to run before the test-compile phase, in which case there will be no classes to include. Or you are running mvn assembly:assembly, in which case the default lifecycle will not be run and the test classes not compiled. You could bind the execution of the assembly plugin to a later phase (e.g. package) to ensure the processing is completed before the assembly is constructed.

However you don't need to use an assembly to package test-classes. This can be done by configuring the jar plugin to package the test jar as follows:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>jar</goal>
          <goal>test-jar</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

By default the test jar will be attached to the project, and when installed/deployed will have the classifier tests.

If you must use the assembly, here is how you bind it to the default lifecycle so that it will be run when package is called.

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <configuration>
    <descriptors>
      <descriptor>src/main/assembly/test-assembly.xml</descriptor>
    </descriptors>
  </configuration>
  <executions>
    <execution>
      <id>make-test-assembly</id>
      <phase>package</phase> <!-- append to the packaging phase. -->
      <goals>
        <goal>single</goal>
      </goals>
    </execution>
  </executions>
</plugin>

If this still does not work, it suggests you are using a non-standard packaging type that doesn't perform the relevant goals for test processing, or your test sources are defined in a non-standard location so they are not being processed. If you are still having trouble can you append the output from your build to your question?

Rich Seller
Thanks for the inputs.The requirement is to create an assembly.I even tried explicitly given the configuration as "test-compile package " [while using eclipse plugin].But still no classes for Test
Hurray..it worked...I found something strange also..I have given the final name of the assembly as XX...but the assembly that is getting created has the name as per the format artifactID-version.jar..Why is this so?
The finalName is only applied for the jar when output to the target location, when it is installed/deployed it will be attached with a classifier that defaults to the assembly's id. This can't be overridden and is really needed so Maven can follow the conventions
Rich Seller
...and glad to help. If you found this answer addressed your problem, you can choose to accept it
Rich Seller
Hi Can you pls clarify the point wrt-defaults to assembly id.Let me tell you in detail whats happening in my proj.I m creating many assemblies(4-5),output to target.1/2of these are not taking their final names(or assembly id) , but as per the format artifactID-version.jar..This is very confusing