views:

31

answers:

1

I have a maven project where I am using the assembly plugin. I typically create my artifacts by running: mvn clean verify assembly:assembly (I have integration tests which I want run separately to unit tests).

When this runs, the assembly plugin is running the unit tests itself. This causes them to be run twice.

Is there a way I can tell the assembly plugin not to run the tests? I am tempted to run this in two steps: 1. mvn clean verify 2. if previous command successful, run mvn assembly:assembly -DskipTests=true

However, this is a little clumsy and would rather the single command.

Thanks, Steven

+1  A: 

When this runs, the assembly plugin is running the unit tests itself. This causes them to be run twice.

The assembly:assembly goal Invokes the execution of the lifecycle phase package prior to executing itself and running it on the command line will thus invoke any phase prior to package. And this includes the test phase.

Is there a way I can tell the assembly plugin not to run the tests?

No. My suggestion would be to create the assembly as part of the build lifecycle instead of invoking the plugin on the command line i.e. to bind it on a particular phase. For example:

<project>
 ...
 <build>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2-beta-5</version>
        <executions>
          <execution>
            <id>create-my-assembly</id>
            <phase>package</phase><!-- change this if not appropriate -->
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              ...
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

And if you don't want the assembly to be created if your integration tests fail, then bind it on a later phase (e.g. post-integration-test or verify).

And if you don't want the assembly to be systematically created, put the above configuration in a profile.

Pascal Thivent
Hi, I already have assembly run automatically on package (phase set to package).However, it just goes and runs the unit tests itself, even when just running: mvn clean packageSo the regular shift through the test phase runs the first set of unit tests, and then assembly's binding to the package phase runs the unit tests again.
Steven
@Steven It doesn't if you bind the right goal i.e. `single`. I suspect that you bound `assembly` which should be used on the command line ONLY.
Pascal Thivent
@Pascal. I am using the attached goal. This is so that it will be uploaded to my repository during releases. I tried build-helper-plugin to attach the artifact before I used the attached goal, but it complained about artifacts with the same ID (or something strange like that).I will have another go with single goal later on. Thanks
Steven
Thanks Pascal, the single goal did the trick.
Steven