title: Maven Lifecycle Woes - 'pre-integration-test'
body: <p>Good afternoon,</p>
  
  <p>I am currently modifying a POM so that as well as compiling the code it creates a deployment package that can be easily run on the target servers.</p>
  
  <p>The parent POM calls many modules that get built in turn.  So that I get all of the build artefacts from these modules into a known location I have added a new module called 'distribution' with its own POM.  This POM has the plugins for Maven Assembly and Maven AntRun.</p>
  
  <p>The assembly plugin is hooked into the 'package' lifecycle:</p>
  
  <pre><code>&lt;plugin&gt;
      &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
      &lt;executions&gt;
           &lt;execution&gt;
               &lt;id&gt;distro-assembly&lt;/id&gt;
               &lt;phase&gt;package&lt;/phase&gt;
               &lt;goals&gt;
                   &lt;goal&gt;single&lt;/goal&gt;
               &lt;/goals&gt;
               &lt;configuration&gt;
                   &lt;descriptors&gt;
                       &lt;descriptor&gt;assembler.xml&lt;/descriptor&gt;
                   &lt;/descriptors&gt;
               &lt;/configuration&gt;
           &lt;/execution&gt;
      &lt;/executions&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>The assembler XML uses both moduleSets and fileSets to bring the necessary files into the output directory.  I use the 'useAllReactorProjects' flag to get the system to pull all the built 'war' files that need to be included in the deployment package.</p>
  
  <pre><code>&lt;assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"&gt;
    &lt;id&gt;bin&lt;/id&gt;
    &lt;formats&gt;
      &lt;format&gt;dir&lt;/format&gt;
      &lt;format&gt;tar.gz&lt;/format&gt;
    &lt;/formats&gt;
    &lt;includeBaseDirectory&gt;false&lt;/includeBaseDirectory&gt;
  
    &lt;moduleSets&gt;
      &lt;moduleSet&gt;
  
        &lt;useAllReactorProjects&gt;true&lt;/useAllReactorProjects&gt;
  
        &lt;includes&gt;
          &lt;include&gt;com.example.fire:fire-apis-admin-pack-sesame-rest&lt;/include&gt;
          &lt;include&gt;com.example.fire:fire-apis-asset-pack-sesame-rest&lt;/include&gt;
          &lt;include&gt;com.example.fire:fire-apis-event-pack-sesame-rest&lt;/include&gt;
          &lt;include&gt;com.example.fire:fire-apis-geonames-pack-sesame-rest&lt;/include&gt;
          &lt;include&gt;com.example.fire:fire-apis-stuff-pack-sesame-rest&lt;/include&gt;
        &lt;/includes&gt;
        &lt;binaries&gt;
          &lt;outputDirectory&gt;modules&lt;/outputDirectory&gt;
          &lt;unpack&gt;false&lt;/unpack&gt;
        &lt;/binaries&gt;
      &lt;/moduleSet&gt;
    &lt;/moduleSets&gt;
  
    &lt;!-- Include the Deployment code --&gt;
    &lt;fileSets&gt;
      &lt;fileSet&gt;
  
          &lt;directory&gt;${almfx.path}&lt;/directory&gt;
          &lt;outputDirectory&gt;almfx&lt;/outputDirectory&gt;
  
          &lt;includes&gt;
              &lt;include&gt;**&lt;/include&gt;
          &lt;/includes&gt;
  
          &lt;useDefaultExcludes&gt;true&lt;/useDefaultExcludes&gt;
  
      &lt;/fileSet&gt;
    &lt;/fileSets&gt;
  
  &lt;/assembly&gt;
  </code></pre>
  
  <p>This all works well and I can see the files in the output directory when I run <code>mvn package</code>.</p>
  
  <p>The next bit is where i am having problems.  I need to do some more work on the package so I am trying to hook into the 'pre-integration-test' lifecycle:</p>
  
  <pre><code>&lt;plugin&gt;
      &lt;artifactId&gt;maven-antrun-plugin&lt;/artifactId&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.ant&lt;/groupId&gt;
              &lt;artifactId&gt;ant&lt;/artifactId&gt;
              &lt;version&gt;1.8.1&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
      &lt;executions&gt;
          &lt;execution&gt;
              &lt;phase&gt;pre-integration-test&lt;/phase&gt;
              &lt;configuration&gt;
                  &lt;target&gt;
                      &lt;echo message="Calling ANT from Maven" /&gt;
                  &lt;/target&gt;
              &lt;/configuration&gt;
              &lt;goals&gt;
                  &lt;goal&gt;run&lt;/goal&gt;
              &lt;/goals&gt;
          &lt;/execution&gt;
      &lt;/executions&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>As you can see I am attempting to use the antrun plugin to do this work.  I am just doing a simple test at the moment and that is to just output something to the screen.</p>
  
  <p>Now when I run <code>mvn pre-integration-test</code> the 'package' phase works as before and I see all the output.  However when it comes to the 'pre-integration-test' phase I get a problem with a missing artifact.</p>
  
  <p>Now I thought that as the system has built the code and it has it all locally then it would not be looking for any other artifacts to pull in.  The artifact that it is looking for is in one of the modules which have been compiled, and as such is not in the local or remote repository.</p>
  
  <p>As I only want to do some work on the output of the 'package' phase I do not need anything to be downloaded, but I am not sure how i can accomplish this.  I have been looking around the net to try and work out how to get around this, but all the examples seem to show something similar to what I am doing.</p>
  
  <p>If anyone has any pointers on what I am doing wrong then please let me know.
  I hope i have provided all the information that is needed, but please let me know if you need anymore and I will be happy to provide it.</p>
  
  <p>Thanks very much in advance,</p>
  
  <p>Russell</p>
  
  <p><strong>UPDATE:  2012-02-08 1450</strong></p>
  
  <p>After Andrews suggestion I modified the distribution POM slightly so that the AntRun Plugin was part of the same 'Package' phase.  I was not able to attach it to the same goal as the AntRun plugin does not have 'single' as a goal so I left it as run.</p>
  
  <p>Unfortunately I am seeing the same problem where the system is trying to download something from the repository that it has already built.  The sort of error I get is:</p>
  
  <pre><code>Downloading: http://nexus/nexus/content/groups/public/com/example/fire/fire-apis/latest-SNAPSH
  OT/fire-apis-latest-20120208.061113-108.jar
  [INFO] ------------------------------------------------------------------------
  [ERROR] BUILD ERROR
  [INFO] ------------------------------------------------------------------------
  [INFO] Failed to resolve artifact.
  
  Missing:
  ----------
  1) com.example.fire:fire-apis:jar:latest-SNAPSHOT
  
    Try downloading the file manually from the project website.
  
    Then, install it using the command:
        mvn install:install-file -DgroupId=com.example.fire -DartifactId=fire-apis -Dversion=latest-20120208.0611
  13-108 -Dpackaging=jar -Dfile=/path/to/file
  
    Alternatively, if you host your own repository you can deploy the file there:
        mvn deploy:deploy-file -DgroupId=com.example.fire -DartifactId=fire-apis -Dversion=latest-20120208.061113
  -108 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
  
    Path to dependency:
          1) com.example.fire:distribution:pom:latest-SNAPSHOT
          2) com.example.fire:fire-apis:jar:latest-SNAPSHOT
  
  ----------
  1 required artifact is missing.
  
  for artifact:
    com.example.fire:distribution:pom:latest-SNAPSHOT
  
  from the specified remote repositories:
    public-mirror (http://nexus/nexus/content/groups/public)
  </code></pre>
  
  <p>I am stumped on this as I thought this would be the way to do this.  I know I am missing something.  I can post a log if it helps, but it will be huge.</p>
  
  <p><strong>UPDATE:  2012-02-09 1130</strong></p>
  
  <p>So that people have a better view of what I am trying to do I have posted some information onto Pastebin.</p>
  
  <p>Parent POM - <a href="http://pastebin.com/adpnZVe1" rel="nofollow">http://pastebin.com/adpnZVe1</a></p>
  
  <p>Distribution Module POM - <a href="http://pastebin.com/bycHcqgk" rel="nofollow">http://pastebin.com/bycHcqgk</a></p>
  
  <p>Maven Debug Log - <a href="http://pastebin.com/dDBV5uNM" rel="nofollow">http://pastebin.com/dDBV5uNM</a></p>
  
  <p>This is a snippet towards the end of the main log file that pertains to the AntRun section.  (The main log file is over 11Mb !!)</p>
  
  <p>To do all this packaging using the <code>useAllReactorProjects</code> flag I followed the example from this page <a href="http://maven.apache.org/plugins/maven-assembly-plugin/examples/multimodule/module-binary-inclusion-simple.html" rel="nofollow">http://maven.apache.org/plugins/maven-assembly-plugin/examples/multimodule/module-binary-inclusion-simple.html</a>.</p>
  
  <p>Thanks.</p>