title: Maven: How to unpack precise files from artifacts in the same output directory?
body: <p>I have several artifacts from the same groupId (<code>org.webjars</code>), and I need to unpack them, and then copy all the contained js files into the same directory.</p>
  
  <p>The artifacts archives have a hierarchy (compressed as a jar) as follows:</p>
  
  <pre><code>artifact1
      - resources
          - webjars
              - ...
                  - sample-1.js
                  - sample-2.js
  </code></pre>
  
  <p>I need at the end that every js file is copied into the same directory without their hierarchy, as follows:</p>
  
  <pre><code>outputDirectory
      - sample-1.js
      - sample-2.js
      - ...
      - sample-n.js
  </code></pre>
  
  <p>The result I can reach is the following one:</p>
  
  <pre><code>outputDirectory
      - artifact-1
          - resources
              - webjars
                  - ...
                      - sample-1.js
                      - sample-2.js
      - ...
      - artifact-m
          - resources
              - webjars
                  - ...
                      - sample-n.js
  </code></pre>
  
  <p>For this purpose, I used the <code>maven-dependency-plugin</code>:</p>
  
  <pre><code>&lt;plugin&gt;
      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
      &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
      &lt;executions&gt;
          &lt;execution&gt;
              &lt;id&gt;unpack org.webjars dependencies&lt;/id&gt;
              &lt;goals&gt;
                  &lt;goal&gt;unpack-dependencies&lt;/goal&gt;
              &lt;/goals&gt;
              &lt;configuration&gt;
              &lt;includeGroupIds&gt;org.webjars&lt;/includeGroupIds&gt;
              &lt;includes&gt;**/*.js&lt;/includes&gt;
              &lt;outputDirectory&gt;${project.build.directory}/static&lt;/outputDirectory&gt;
              &lt;/configuration&gt;
          &lt;/execution&gt;
      &lt;/executions&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>Is there a magical option of this plugin to do this, or should I need another plugin to complete the job?</p>
  
  <p>EDIT: Here is the solution I finally used:</p>
  
  <pre><code>&lt;plugin&gt;
      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
      &lt;artifactId&gt;maven-antrun-plugin&lt;/artifactId&gt;
      &lt;executions&gt;
          &lt;execution&gt;
              &lt;id&gt;copy org.webjars dependency to jar&lt;/id&gt;
              &lt;phase&gt;package&lt;/phase&gt;
              &lt;goals&gt;&lt;goal&gt;run&lt;/goal&gt;&lt;/goals&gt;
              &lt;configuration&gt;
                  &lt;target&gt;
                      &lt;copy todir="${project.build.directory}/classes/static" flatten="true"&gt;
                          &lt;fileset dir="${project.build.directory}/static"&gt;
                                       &lt;include name="**/*.js"/&gt;
                          &lt;/fileset&gt;
                      &lt;/copy&gt;
                  &lt;/target&gt;
              &lt;/configuration&gt;
            &lt;/execution&gt;
      &lt;/executions&gt;
  &lt;/plugin&gt;
  &lt;!-- Force the generation of the jar to be done after the javascript dependencies have been copied.
  Note : This is a half solution, as the jar is generated twice: a first time before the javascript get copied, and
  another one after. As a result, there is the correct jar, but after two creations... --&gt;
  &lt;plugin&gt;
      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
      &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
      &lt;executions&gt;
          &lt;execution&gt;
              &lt;id&gt;Force the jar-plugin to be called after the javascripts dependencies have been copied to be embedded&lt;/id&gt;
              &lt;phase&gt;package&lt;/phase&gt;
              &lt;goals&gt;&lt;goal&gt;jar&lt;/goal&gt;&lt;/goals&gt;
             &lt;/execution&gt;
         &lt;/executions&gt;
  &lt;/plugin&gt;
  </code></pre>