views:

726

answers:

3

I am using Maven 2.0.9 to build a multi module project. I have defined the assembly plugin in my parent pom. I can get my assemblies built using

mvn install assembly:assembly

This command runs the tests twice, once during install phase and another during assembly. I tried assembly:single but it throws an error. Any help to get my assemblies built without running the tests twice is much appreciated.

+2  A: 

Invoking the assembly mojo will cause Maven to build the project using the normal lifecycle, up to the package phase. So, when you run:

mvn install assembly:assembly

you are actually telling maven to run a few things twice and this includes the test phase as you can see in the documentation of the default lifecycle.

To avoid this, consider running only:

mvn assembly:assembly

Or bind the plugin on a project's build lifecycle:

<project>
  ...
  <build>
    ...
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          ...
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id> <!-- this is used for inheritance merges -->
            <phase>package</phase> <!-- append to the packaging phase. -->
            <goals>
              <goal>single</goal> <!-- goals == mojos -->
            </goals>
          </execution>
        </executions>
      </plugin>
      ...
</project>
Pascal Thivent
A: 

I tried your suggestion earlier, doesn't work for a multi module project. Should have posted this error message in the first place. Running

mvn install mvn assembly:single

or

mvn install mvn assembly:assembly

or

mvn install assembly:single

or

mvn package

generates

[ERROR] BUILD ERROR [INFO] ------------------------------------------------------------------------ [INFO] Failed to create assembly: Artifact: com.BLAH.BLAH:jar:VERSION (included by module) does not have an artifact with a file. Please ensure the package phase is run before the assembly is generated.

Though all the jars are built and installed, assembly plugin doesnt seem to recognize it.

+1  A: 

I think the error message is misleading , it suggests you need to run the "package" phase within the SAME maven invocation as the assembly plugin's invocation itself.

Did you try "mvn package assembly:assembly" or "mvn install assembly:assembly" ?

Works for me under Linux , JDK 1.6.0_16 , Maven 2.2.1 , Assembly Plugin 2.2-beta-4.

JavaGuy
The POM snippet suggested above (binding assembly plugin to the 'ackage phase) should work equally , just keep in mind that then you don't need to explicitly invoke the assembly plugin on the command line. A 'mvn package' (or 'mvn install') will automatically create the assembly as well. Not sure if I've ever used the assembly plugin in that way though. I usually invoke it explicitly because I often don't care about the assembly being generated.
JavaGuy
I tied assembly plugin to package or install phase, ram mvn install or mvn package. Still the same error. This happens only in multi module project.