title: How to stop Maven's verify phase rebuilding the artifact?
body: <p>Imagine a Java project built using Maven for which I have:</p>
  
  <ul>
  <li>some fast-running unit tests that:
  <ul>
  <li>developers should run before committing</li>
  <li>my CI server (Hudson, FWIW) should run upon detecting a new commit, giving almost instant feedback in case of failures</li>
  </ul></li>
  <li>some slow-running automated acceptance tests that:
  <ul>
  <li>developers can run if they choose, e.g. to reproduce and fix failures</li>
  <li>my CI server should run after successfully running the unit tests</li>
  </ul></li>
  </ul>
  
  <p>This seems like a typical scenario. Currently, I'm running:</p>
  
  <ul>
  <li>the unit tests in the "test" phase</li>
  <li>the acceptance tests in the "verify" phase</li>
  </ul>
  
  <p>There are two CI jobs configured, both pointing to the project's VCS branch:</p>
  
  <ol>
  <li>"Commit Stage", which runs "mvn package" (compile and unit test the code, build the artifact), which if successful, triggers:</li>
  <li>"Automated Acceptance Tests", which runs "mvn verify" (set up, run, and tear down the acceptance tests)</li>
  </ol>
  
  <p>The problem is that job 2 unit tests and builds the artifact-under-test all over again (because the verify phase automatically invokes the package phase). This is undesirable for several reasons (in decreasing importance):</p>
  
  <ul>
  <li>the artifact created by job 2 might not be identical to that created by job 1 (e.g. if there has been a new commit in the meantime)</li>
  <li>lengthens the feedback loop to the developer who made the commit (i.e. takes longer for them to find out they broke the build)</li>
  <li>wastes resources on the CI server</li>
  </ul>
  
  <p>So my question is, how can I configure job 2 to use the artifact created by job 1?</p>
  
  <p><em>I realise I could just have one CI job that runs "mvn verify", which would create the artifact only once, but I want to have the separate CI jobs described above in order to implement a Farley-style deployment pipeline.</em></p>
  
  <hr>
  
  <p>In case it helps anyone, here's the full Maven 2 POM of "project 2" in the accepted answer:</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;com.example.cake&lt;/groupId&gt;
      &lt;artifactId&gt;cake-acceptance&lt;/artifactId&gt;
      &lt;version&gt;1.0&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
      &lt;name&gt;Cake Shop Acceptance Tests&lt;/name&gt;
      &lt;description&gt;
          Runs the automated acceptance tests for the Cake Shop web application.
      &lt;/description&gt;
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;!-- Compiler --&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.3.1&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;${java.version}&lt;/source&gt;
                      &lt;target&gt;${java.version}&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;!-- Suppress the normal "test" phase; there's no unit tests --&gt;
              &lt;plugin&gt;
                  &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.5&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;skipTests&gt;true&lt;/skipTests&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;!-- Cargo (starts and stops the web container) --&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.codehaus.cargo&lt;/groupId&gt;
                  &lt;artifactId&gt;cargo-maven2-plugin&lt;/artifactId&gt;
                  &lt;version&gt;1.0.5&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;start-container&lt;/id&gt;
                          &lt;phase&gt;pre-integration-test&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;start&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                      &lt;execution&gt;
                          &lt;id&gt;stop-container&lt;/id&gt;
                          &lt;phase&gt;post-integration-test&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;stop&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
                  &lt;configuration&gt;
                      &lt;!-- Don't wait for CTRL-C after starting the container --&gt;
                      &lt;wait&gt;false&lt;/wait&gt;
  
                      &lt;container&gt;
                          &lt;containerId&gt;jetty7x&lt;/containerId&gt;
                          &lt;type&gt;embedded&lt;/type&gt;
                          &lt;timeout&gt;20000&lt;/timeout&gt;
                      &lt;/container&gt;
  
                      &lt;configuration&gt;
                          &lt;properties&gt;
                              &lt;cargo.servlet.port&gt;${http.port}&lt;/cargo.servlet.port&gt;
                          &lt;/properties&gt;
                          &lt;deployables&gt;
                              &lt;deployable&gt;
                                  &lt;groupId&gt;${project.groupId}&lt;/groupId&gt;
                                  &lt;artifactId&gt;${target.artifactId}&lt;/artifactId&gt;
                                  &lt;type&gt;war&lt;/type&gt;
                                  &lt;properties&gt;
                                      &lt;context&gt;${context.path}&lt;/context&gt;
                                  &lt;/properties&gt;
                              &lt;/deployable&gt;
                          &lt;/deployables&gt;
                      &lt;/configuration&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;!-- Failsafe (runs the acceptance tests) --&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-failsafe-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.6&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;integration-test&lt;/id&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;integration-test&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                      &lt;execution&gt;
                          &lt;id&gt;verify&lt;/id&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;verify&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
                  &lt;configuration&gt;
                      &lt;includes&gt;
                          &lt;include&gt;**/*Test.java&lt;/include&gt;
                      &lt;/includes&gt;
                      &lt;skipTests&gt;false&lt;/skipTests&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
      &lt;dependencies&gt;
              &lt;!-- Add your tests' dependencies here, e.g. Selenium or Sahi,
                  with "test" scope --&gt;
          &lt;dependency&gt;
              &lt;!-- The artifact under test --&gt;
              &lt;groupId&gt;${project.groupId}&lt;/groupId&gt;
              &lt;artifactId&gt;${target.artifactId}&lt;/artifactId&gt;
              &lt;version&gt;${target.version}&lt;/version&gt;
              &lt;type&gt;war&lt;/type&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
      &lt;properties&gt;
          &lt;!-- The artifact under test --&gt;
          &lt;target.artifactId&gt;cake&lt;/target.artifactId&gt;
          &lt;target.version&gt;0.1.0-SNAPSHOT&lt;/target.version&gt;
          &lt;context.path&gt;${target.artifactId}&lt;/context.path&gt;
          &lt;http.port&gt;8081&lt;/http.port&gt;
          &lt;java.version&gt;1.6&lt;/java.version&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;/properties&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Note that even though this "tests" project doesn't create an artifact, it has to use some kind of packaging (I used "jar" here), otherwise no tests are run in the verify phase.</p>