title: Manually attach main artifact if built by maven-assembly-plugin
body: <p>I am having problems building a maven project. I have a requirement to produce <em>deterministic</em> jar files, which must be binary-consistent across different builds and versions, in case there are no source code changes in between these builds. For the purpose, I have used <a href="http://gary-rowe.com/agilestack/2013/08/08/how-to-create-a-deterministic-jar/" rel="nofollow noreferrer">this article</a> for guidance.</p>
  
  <p>I have successfully managed to build my jars and they are consistent up to my requirements. Here is my configuration:</p>
  
  <pre><code>  &lt;plugin&gt;
      &lt;artifactId&gt;maven-antrun-plugin&lt;/artifactId&gt;
      &lt;version&gt;1.7&lt;/version&gt;
      &lt;executions&gt;
        &lt;execution&gt;
          &lt;id&gt;step-1-remove-timestamp&lt;/id&gt;
          &lt;phase&gt;prepare-package&lt;/phase&gt;
          &lt;configuration&gt;
            &lt;target&gt;
              &lt;touch datetime="01/01/2015 00:10:00 am"&gt;
                &lt;fileset dir="target/classes"/&gt;
                &lt;fileset dir="src"/&gt;
              &lt;/touch&gt;
            &lt;/target&gt;
          &lt;/configuration&gt;
          &lt;goals&gt;
            &lt;goal&gt;run&lt;/goal&gt;
          &lt;/goals&gt;
        &lt;/execution&gt;
        &lt;execution&gt;
          &lt;id&gt;step-3-rename-assembly&lt;/id&gt;
          &lt;phase&gt;package&lt;/phase&gt;
          &lt;configuration&gt;
            &lt;target&gt;
              &lt;copy file="${project.build.directory}/${project.build.finalName}-deterministic.zip"
                    tofile="${project.build.directory}/${project.build.finalName}.jar"/&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;
  
    &lt;plugin&gt;
      &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
      &lt;version&gt;2.2.1&lt;/version&gt;
      &lt;configuration&gt;
        &lt;descriptors&gt;
          &lt;descriptor&gt;src/main/assembly/zip.xml&lt;/descriptor&gt;
        &lt;/descriptors&gt;
      &lt;/configuration&gt;
      &lt;executions&gt;
        &lt;execution&gt;
          &lt;id&gt;step-2-make-assembly&lt;/id&gt;
          &lt;phase&gt;prepare-package&lt;/phase&gt;
          &lt;goals&gt;
            &lt;goal&gt;single&lt;/goal&gt;
          &lt;/goals&gt;
        &lt;/execution&gt;
      &lt;/executions&gt;
    &lt;/plugin&gt;
  </code></pre>
  
  <p>In the above code I build and package the jar as a zip, then copy the zip over the expected jar artifact.<br>
  The problem with the above, is that maven still executes the <code>maven-jar-plugin</code>, so the manually assembled jar is overwritten by the one of the <code>maven-jar-plugin</code>. I do not want to use this jar, since it is not consistent with my requirements.</p>
  
  <p>So, I have disabled the <code>maven-jar-plugin</code> execution, by explicitly setting it to run for an invalid phase, like below: (saw that from <a href="https://stackoverflow.com/questions/4101750/disable-the-execution-default-jar">other posts here</a>)</p>
  
  <pre><code>  &lt;plugin&gt;
      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
      &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
      &lt;version&gt;2.5&lt;/version&gt;
      &lt;executions&gt;
        &lt;execution&gt;
          &lt;id&gt;default-jar&lt;/id&gt;
          &lt;phase&gt;never&lt;/phase&gt;
          &lt;configuration&gt;
            &lt;finalName&gt;unwanted&lt;/finalName&gt;
            &lt;classifier&gt;unwanted&lt;/classifier&gt;
          &lt;/configuration&gt;
        &lt;/execution&gt;
      &lt;/executions&gt;
    &lt;/plugin&gt;
  </code></pre>
  
  <p>Everything seems fine, until I discovered my main jar artifact is never installed in the <code>.m2</code> directory. To correct this, I also added the <code>maven-helper-plugin</code> so that I manually attach any artifacts I produce from the assembler plugin:</p>
  
  <pre><code>  &lt;plugin&gt;
      &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
      &lt;artifactId&gt;build-helper-maven-plugin&lt;/artifactId&gt;
      &lt;version&gt;1.9.1&lt;/version&gt;
      &lt;executions&gt;
        &lt;execution&gt;
          &lt;id&gt;attach-instrumented-jar&lt;/id&gt;
          &lt;phase&gt;verify&lt;/phase&gt;
          &lt;goals&gt;
            &lt;goal&gt;attach-artifact&lt;/goal&gt;
          &lt;/goals&gt;
          &lt;configuration&gt;
            &lt;artifacts&gt;
              &lt;artifact&gt;
                &lt;file&gt;${project.build.directory}/${project.build.finalName}.jar&lt;/file&gt;
                &lt;type&gt;jar&lt;/type&gt;
              &lt;/artifact&gt;
            &lt;/artifacts&gt;
          &lt;/configuration&gt;
        &lt;/execution&gt;
      &lt;/executions&gt;
    &lt;/plugin&gt;
  </code></pre>
  
  <p>This leads to an error I am unable to solve:</p>
  
  <blockquote>
    <p>[ERROR] Failed to execute goal org.codehaus.mojo:build-helper-maven-plugin:1.9.1:attach-artifact (attach-instrumented-jar) on project my-project: Execution attach-instrumented-jar of goal org.codehaus.mojo:build-helper-maven-plugin:1.9.1:attach-artifact failed: For artifact {full-name-of-my-project.jar}: <strong>An attached artifact must have a different ID than its corresponding main artifact.</strong> -> [Help 1]</p>
  </blockquote>
  
  <p>Is there a way to overcome this issue? I've checked for solutions, and most recommend using classifiers, but I want to install the main artifact as would the <code>maven-jar-plugin</code>. Other software we are developing will require the standard jar dependency, and we want to avoid complicating our setup by introducing classifiers unreasonably.</p>