title: How to force maven to run build-lifecycle before site-lifecycle?
body: <p>After spending several hours trying to find out whats the problem I come to the conclusion that I need to know:</p>
  
  <p><strong>How can I force maven to execute the lifecycle phases clean, build and site in exact this order: <code>clean -&gt; build -&gt; site</code>?</strong></p>
  
  <p>Problem / scenario:</p>
  
  <p>I have to multimodule projects with identical moduls:</p>
  
  <pre><code>pSuccess
  |-pSuccessClient
  |-pSuccessEJB (has pSuccessClient as dependency)
  |-pSuccessEAR (has pSuccessEJB as dependency)
  </code></pre>
  
  <p>and</p>
  
  <pre><code>pFail
  |-pFailClient
  |-pFailEJB (has pFailClient as dependency)
  |-pFailEAR (has pFailEJB as dependency)
  </code></pre>
  
  <p>Both projects have distribution repositories for snapshots and releases in our central nexus artefact repository but none of them has been deployed to it, meaning the nexus is empty.</p>
  
  <p>When I run <code>mvn clean package site</code> on the <code>pSuccess</code>-project the target directory is deleted (clean-lifecycle), then the modules are all build (build-lifecycle) and finally the reports are generated (site-lifecycle) correctly on the freshly build modules - BUILD SUCCESS! While "debugging" the process I figured out that during the build-lifecycle the needed clientDependency is placed in the lokal maven repository and then used for the EJB, same with the EJB for the EAR module. Working smoothly as expected.</p>
  
  <p>But when I do the same on the <code>pFail</code>-project maven executes the site-lifecycle after the clean-lifecycle and <strong>before</strong> the build-lifecycle. As you can expect this results in a failed build as maven can't find the needed dependency (Client) for the EJB. This is quite locically as it hasn't been build yet. I can enforce this result every time I run the command. There's not phase of the build-lifecycle be run - no compilation, just nothing. Maven tries to execute the site-lifecycle first. The build is only successfull when I run a <code>mvn clean deploy</code> and then another <code>mvn clean package site</code>, becuase then the artefact is read from the nexus. But again site-lifecycle is executed before build-lifecycle. <strong>Note</strong> Building the project only via <code>mvn clean package</code> works fine without any problems. All modules are build in the correct order. But when I add the <code>site</code> lifecycle it fails.</p>
  
  <p>I read the <a href="https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html" rel="nofollow noreferrer">maven documentation about lifecycle</a> but I can't figure out why <code>site</code> is run before <code>build</code>. In some questions here on SO I read that plugins, which shall be executed in the same phase, are executed in the order they are listed in the <code>pom.xml</code>. So I checked that too, but the <code>&lt;build&gt;</code> tag is definied before the <code>&lt;reporting&gt;</code> tag.</p>
  
  <p>So why is maven executing the site-lifecycle before the build-lifecycle in one of my project and how can I force maven to execute the lifecycles in the right order: <code>clean -&gt; build -&gt; site</code> ?</p>
  
  <p>P.S: I run all maven commands on command line in windows 7.</p>
  
  <p><strong>edit</strong></p>
  
  <p>I know about the lifecycles and phases, meaning I know what's the differenze between <code>package</code>, <code>install</code>, <code>deploy</code> is - that is not part of the question!</p>
  
  <p>For those who do not believe about the execution order: This is the output when I run <code>mvn clean install site</code>, showing that site-lifecycle is executed before build-lifecycle. It doesn't matter if I run <code>mvn clean package site</code> or <code>mvn clean install site</code>. Again, running single <code>mvn clean package</code>(or install) works fine, but not when I want to generate site too. Then site is executed first.</p>
  
  <p><a href="https://i.stack.imgur.com/9Dvu7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9Dvu7.png" alt="Build-failure"></a></p>