title: How to add a dynamically generated file to my ear archive?
body: <p>Basically, we have an ear archive that has multiple dependencies. In those dependencies, we plan on filling the manifest or some properties file with multiple properties:</p>
  
  <ul>
  <li>build timestamp</li>
  <li>buildnumber (from CI server)</li>
  <li>groupId</li>
  <li>artifactId</li>
  <li>version</li>
  </ul>
  
  <p>This should already be possible for individual artifacts that are built by our CI server, and this is also not really the problem I'm having.</p>
  
  <hr>
  
  <p>Now I use maven for building my <strong>ear</strong> archive, with the maven-ear-plugin. My idea was to just use a groovy script (executed by gmaven-plus) that will read all the jar archives, and fetch the manifest. Then I can rewrite the manifest of the ear archive, or write my own properties file that contains the info I want.</p>
  
  <pre><code>import org.apache.commons.io.FileUtils
  import java.util.jar.JarFile
  
  def path = "target/${project.name}-${project.version}"
  def artifactDir = new File(path)
  def output = new File("$path/META-INF/build-info.properties")
  
  def lines = []
  
  artifactDir.listFiles().each { file-&gt;
      if (file.isFile() &amp;&amp; (file.name.endsWith(".war") || file.name.endsWith(".jar"))) {
          def jar = new JarFile(file)
          def manifest = jar.manifest
          println "processing: $file.name"
          println manifest.mainAttributes
          println jar.properties
          manifest.mainAttributes.keySet().each { attrKey-&gt;
              def val = manifest.mainAttributes.getValue(attrKey.toString())
              lines &lt;&lt; "$file.name.$attrKey=$val"
          }
      }
  }
  
  FileUtils.writeLines(output, lines as Collection&lt;?&gt;
  </code></pre>
  
  <p>)</p>
  
  <p>This script works fine, and will write the <code>build-info.properties</code> file with all the info I'd like to be in there.</p>
  
  <p>This is the plugin configuration:</p>
  
  <pre><code>&lt;plugin&gt;
      &lt;groupId&gt;org.codehaus.gmavenplus&lt;/groupId&gt;
      &lt;artifactId&gt;gmavenplus-plugin&lt;/artifactId&gt;
      &lt;version&gt;1.5&lt;/version&gt;
      &lt;executions&gt;
          &lt;execution&gt;
              &lt;id&gt;create-manifest&lt;/id&gt;
              &lt;phase&gt;package&lt;/phase&gt;
              &lt;goals&gt;
                  &lt;goal&gt;execute&lt;/goal&gt;
              &lt;/goals&gt;
          &lt;/execution&gt;
      &lt;/executions&gt;
      &lt;configuration&gt;
          &lt;scripts&gt;
              &lt;script&gt;file:///${project.basedir}/src/main/gmaven/create-manifest.groovy&lt;/script&gt;
          &lt;/scripts&gt;
      &lt;/configuration&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>Of course, you'll already notice what's wrong with this: the <code>package</code>phase is too late, <code>prepare-package</code> is too early, because the ear plugin has not yet copied the dependencies I'm scanning.</p>
  
  <hr>
  
  <h2>Conclusion</h2>
  
  <p>Well, the obvious thing to do would be to unzip the ear produced, and then add the file manually, then zip it again. But that seems pretty dirty to me, and I was wondering whether there is no cleaner way to do this?</p>
  
  <p>Perhaps by leverageing gradle, or some option of the maven-ear-plugin I have not yet discovered? Or just in general, how would you tackle the specific problem I am facing here?</p>